Page 1 of 1

[SOLVED] Simple loop through an array

Posted: Sat Jul 23, 2005 7:17 pm
by charp
Perhaps I'm just tired :?, but I cannot figure out what I'm doing wrong here:

Code: Select all

$results=mysql_query("SELECT post_id FROM $table");
$row=mysql_fetch_array($results);
while ($row=mysql_fetch_array($results)) { 
$entry=$row["post_id"];
echo $entry.'<br>';
}
All it's supposed to do is list all the 'post_id' values from the table. But for some reason, it always starts on the second entry and skips the first. The results are the same even if I change to a different column in the table.

Thanks in advance.

Re: Simple loop through an array

Posted: Sat Jul 23, 2005 7:21 pm
by nielsene
charp wrote:Perhaps I'm just tired :?, but I cannot figure out what I'm doing wrong here:

Code: Select all

$results=mysql_query("SELECT post_id FROM $table");
$row=mysql_fetch_array($results);
while ($row=mysql_fetch_array($results)) { 
$entry=$row["post_id"];
echo $entry.'<br>';
}
All it's supposed to do is list all the 'post_id' values from the table. But for some reason, it always starts on the second entry and skips the first. The results are the same even if I change to a different column in the table.

Thanks in advance.
Remove line 2.

Posted: Sat Jul 23, 2005 7:27 pm
by charp
Thanks nielsene, that worked.

Even after I had it working it took me a couple of moments to see what I was doing wrong! Two instance of mysql_fetch_array-- Duh :oops:

Posted: Sat Jul 23, 2005 7:29 pm
by nielsene
yeah, its always those simple things that you can't find in your own code.... The hours I've wasted with similiar type bugs.....