Click to See Complete Forum and Search --> : First row not being returned


stinkysGTI
06-29-2008, 07:03 PM
For some reason, I'm not getting the first row from any selection. I even verified it in PHPMyAdmin and ran the query there; it returned all the correct rows. It's only when I run the script on a page that the first row doesn't get returned. Anyone know why? Could it be the mysql_fetch_array ?

Here's my script:

mysql_connect("", "", "") or die(mysql_error());
mysql_select_db("DBNAME") or die(mysql_error());
$result = mysql_query("select * from cars where(model='".$_POST['model']."')") or die(mysql_error());
$row = mysql_fetch_array( $result );

echo '<select>';
while($row = mysql_fetch_array($result)){
echo "<option>".$row['Trim']."</option>";
}
echo '</select>';


Thanks for any help you may have.

NogDog
06-29-2008, 07:32 PM
The (apparently useless) call to mysql_fetch_array() before you start the while loop is advancing the result set row pointer, thus the first row does not get accessed within the loop.

stinkysGTI
06-30-2008, 10:55 AM
What can I use instead of the fetch array? I'm kinda new to mysql :\

NogDog
06-30-2008, 11:35 AM
As far as I can see from the code provided, there is no reason for that first fetch (before the while loop), so just delete (or comment out) that line.

stinkysGTI
06-30-2008, 12:43 PM
Thanks NogDog; after you mentioned it, I realized that was in there twice and for no reason really.

Now it works just right :)
Thank you