stvchez Posted April 21, 2007 Share Posted April 21, 2007 I'm not sure what is going on because I have iteration working on my other pages. basically, with the attached code, I am getting the same first record 15 times. am I missing anything? //code $query = "SELECT * FROM testTableNames ORDER BY ID"; $result = mysql_query($query, $link); ?> <table> <tr> <td>ID</td> <td>First Name</td> <td>Last Name</td> <td>City</td> <td>State</td> <td>Zip Code</td> </tr> <?php // get number of rows $num=mysql_numrows($result); echo"debug num rows: $num"; // set variables $FirstName=mysql_result($result,$i,"FirstName"); $LastName=mysql_result($result,$i,"LastName"); $Address1=mysql_result($result,$i,"Address1"); $City=mysql_result($result,$i,"City"); $State=mysql_result($result,$i,"State"); $ZipCode=mysql_result($result,$i,"ZipCode"); $ID=mysql_result($result,$i,"ID"); $i=0; while ($i < $num) { ?> <tr> <td> <?php echo$ID ?> </td> <td><?php echo$FirstName ?></td> <td> <?php echo$LastName ?> </td> <td> <?php echo$City ?> </td> <td> <?php echo$State ?> </td> <td> <?php echo$ZipCode ?> </td> </tr> <?php $i++; } ?> </table> Link to comment https://forums.phpfreaks.com/topic/48035-rs-question/ Share on other sites More sharing options...
taith Posted April 21, 2007 Share Posted April 21, 2007 well... mysql_fetch_array(); is MUCH easier... but if you inist on doing it this way... $query = "SELECT * FROM testTableNames ORDER BY ID"; $result = mysql_query($query); ?> <table> <tr> <td>ID</td> <td>First Name</td> <td>Last Name</td> <td>City</td> <td>State</td> <td>Zip Code</td> </tr> <?php $num=mysql_num_rows($result); echo"debug num rows: $num"; $i=0; while($i < $num){ $FirstName=mysql_result($result,$i,"FirstName"); $LastName=mysql_result($result,$i,"LastName"); $Address1=mysql_result($result,$i,"Address1"); $City=mysql_result($result,$i,"City"); $State=mysql_result($result,$i,"State"); $ZipCode=mysql_result($result,$i,"ZipCode"); $ID=mysql_result($result,$i,"ID"); ?> <tr> <td><?php echo$ID ?></td> <td><?php echo$FirstName ?></td> <td><?php echo$LastName ?></td> <td><?php echo$City ?></td> <td><?php echo$State ?></td> <td><?php echo$ZipCode ?></td> </tr> <?php $i++; } ?> </table> Link to comment https://forums.phpfreaks.com/topic/48035-rs-question/#findComment-234795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.