Jump to content

[SOLVED] list shows incorrect numer of records


Peterson

Recommended Posts

Hello. Thanx for look. This is for me unbelievable...

 

I want display all names beginning with letter "A"

(There is 9 names beginning with A in my database)

 

- when I run SQL query on server, it show proper list of names - 9

SELECT name FROM database WHERE name LIKE 'A%'

 

- when I check mysql_fetch_row() from my php code, if shows real number - 9

 

BUT!!!

when I run this code, it shows only 8 names and does not show the first one.

 

$result = mysql_query("SELECT name FROM database WHERE name LIKE 'A%' ");
$row = mysql_fetch_row($result);

echo mysql_num_rows($result)."<br>";
// Shows number 9

WHILE ($row = mysql_fetch_row($result))
{
echo $row[0]."<br>";
}
// List only 8 names and does not list the first one

 

Please, what's wrong? I found this simple code recommended in all examples on the internet...

 

Basically the issue is you're skipping the first row.  You call "$row = mysql_fetch_row($result);" right after the query, then again in the while loop before anything is output.

 

Just take out that first mysql_fetch_row line.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.