Re: Troubleshooting mysql_fetch_array - I'm stumped!

From: Date: Wed, 09 Aug 2000 02:15:57 +0000
Subject: Re: Troubleshooting mysql_fetch_array - I'm stumped!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-10826@lists.php.net to get a copy of this message
Michael Stembridge wrote:
See sample code below, or click here for a text version: http://www.georgiaoffroad.com/sample.txt As it stands, the fist row (Version) prints to the screen (data from the 'techman' database, that is); every row thereafter is blank.
You need to reset() the $myrow array. But, you don't need to call it every time you want to print a cell. Just stick the while loop around the whole thing, and print $myrow['column'] in each cell. <?php /* very short example */ print '<table>'; while ($myrow = @mysql_fetch_array($result)) { print '<tr>'; print "<td>$myrow['first']</td>"; print "<td>$myrow['second']</td>"; print "<td>$myrow['third']</td>"; print "<td>$myrow['fourth']</td>"; print '</tr>'; } print '</table>'; ?> That way you don't need to reset() the array because you're only using it once. Other than that, you need a reset($myrow) before each new while loop. Better yet, use mysql_fetch_object() Brian

« previous php.general (#10826) next »