View Full Version : SQL query not working properly

08-10-2006, 11:09 PM
I've just recently decided to dabble into MySQL with PHP. So far so good, except for one thing. My script executes fine, no errors, but for some reason it will not grab the first row in my table.

What I mean is this:

Row 1
Row 2
Row 3

In my PHP script, it grabs the information from the database and just displays it. It will display "Row 2 data <br> Row 3 data", but for some reason, it will not display the data in Row 1.

Here's my script (pretty simple):

mysql_select_db($database) or die("Unable to select database");

$result = mysql_query("SELECT * FROM users") or die(mysql_error());

$row = mysql_fetch_array($result);

while($row = mysql_fetch_array($result)){
echo $row['USERID']. " - ". $row['NAME'];
echo "<br>";


Here's my script running right now, for a better example: Clicky (

Any ideas?

Thanks in advance for the help.

08-10-2006, 11:22 PM
Get rid of the line where you are assigning $row before the while block. You don't need to do that, it will do it before the first iteration of the block.

Right now with that there, you are basically skipping over the first row.

08-10-2006, 11:44 PM
Ah, worked perfectly. Thank you very much!