php while loop

Associate
Joined
18 Sep 2003
Posts
2,368
I'm running a while loop to spit some info out from my database. The problem is the code isn't displaying the very first item in the array - does anyone know why?

<?
// GETS bookies from DB
$query = ("SELECT * FROM bookmakers WHERE status='active' AND type='Sportsbook' ORDER BY id_name");
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$row = mysql_fetch_array($result);

while ($row = mysql_fetch_array($result)) {
?>


<tr valign="middle">
<td class="left-link"><a href="sports/<? echo $row["id_name"];?>.php" title="<? echo $row["bookmaker"];?>"><? echo $row["bookmaker"];}?></a></td>
</tr>

Thanks :)
 
Last edited:
Inquisitor said:
You need to remove $row = mysql_fetch_array($result); from before the loop. Remember, the condition for the while loop is evaluated before every iteration, including the first, so if you've already got the row it will be discarded.
Thank you, a simple resolution indeed - I can see what I was doing wrong.
 
Back
Top Bottom