PDA

View Full Version : PHP Failing To Output First Row


Pennimus
12-25-2005, 11:17 PM
Hi,

I'm using the following code to output the contents of my database, which is working fine apart from the fact that it seems to be ignoring the first result.


$sql=mysql_connect ($host, $user, $pass) or die (mysql_error());
mysql_select_db ($data) or die (mysql_error());
$result = mysql_query ("SELECT tag, name, description FROM `tricktionary` WHERE alpha='a' ORDER BY `name` ASC") or die(mysql_error());
$trick = mysql_fetch_array ($result);



while($trick = mysql_fetch_array($result)){
echo '<div class="focus"><h2 id="'. $trick['tag'] .'">'. $trick['name'] .'</h2><p>'. $trick['description'] .'</p></div>';}


I've triple checked that the actual database entry in question has a value of 'a' for 'alpha', which it does, so is there something wrong with the while statement?

Thanks
Adam

PS: Merry christmas!

vinyl-junkie
12-26-2005, 12:07 AM
Get rid of this statement:

$trick = mysql_fetch_array ($result);

This is a common mistake. You're reading the first record with that statement, then not doing anything with it. Your while loop is what's really doing the record processing.

Pennimus
12-26-2005, 12:31 AM
:thumbsup: Wicked, thanks for that.