...

View Full Version : SQL query not working properly



Drevin
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):


<?
$user="xxxxx";
$password="xxxxx";
$database="xxxxx";
mysql_connect(localhost,$user,$password);
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>";
}

mysql_close();
?>

Here's my script running right now, for a better example: Clicky (http://24.69.32.174:8080/nc_db/nc_querytest2.php)

Any ideas?

Thanks in advance for the help.

oracleguy
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.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum