Q about a PHP script

Started by Puritan, 02 January 2012, 18:55:55

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Puritan

I've added a small PHP script that counts rows from the database.
This is put on this page: http://www.scent-88.com/mapbase/maplistings.php
Now, the counter displays two more maps than it should (display=35 but there is only 33 maps registered)  :o
I think the script maybe are counting the first (zero) row and maybe the last row who is not filled in yet..


Code:


mysql_select_db ("database"); 
$result = mysql_query("SELECT * FROM table"); 
 
$num_rows = mysql_num_rows($result); 
 
// Display the results 
 
echo $num_rows;




Anyone have an idea on how to change the script?
Bitter words mean little to me. Autumn winds will blow right through me
And someday in the mist of time, when they asked me if I knew you
I'd smile and say you were a friend of mine, and the sadness would be lifted from my eyes
Oh when I'm old and wise

Forge

If nobody here has an answer, Tx at Duke4 might know.
Take it down to the beach with a hammer and pound sand up your ass

Puritan

I also tried this code:
Guess what?
Same result  :-[


$query = ("SELECT * FROM $table"); 
 
$result = mysql_query($query) or die("Error in query: $query. " .
$row = mysql_fetch_row($result);

$columnCount = count($row);


Bitter words mean little to me. Autumn winds will blow right through me
And someday in the mist of time, when they asked me if I knew you
I'd smile and say you were a friend of mine, and the sadness would be lifted from my eyes
Oh when I'm old and wise

Forge

some examples from google searching:


mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

----------------------------------------------------------

$query = "SELECT type, COUNT(name) FROM products GROUP BY type";
   
$result = mysql_query($query) or die(mysql_error());

----------------------------------------------------------

$query = "SELECT COUNT(1) FROM table");
$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_row($result);

echo $row[0];

-------------------------------------------------------

Take it down to the beach with a hammer and pound sand up your ass

Puritan

^Thanks for your input  ;)
I've tried those too...


But I found one error: Now there is 35 maps in the base but it displays 36.
The last 'extra' entry must be the (zero) line in SQL base.
I don't dare to delete that line at this stage.


I think we have to live with that 'extra' map for a while  :)
Bitter words mean little to me. Autumn winds will blow right through me
And someday in the mist of time, when they asked me if I knew you
I'd smile and say you were a friend of mine, and the sadness would be lifted from my eyes
Oh when I'm old and wise