hoponhiggo Posted September 20, 2011 Share Posted September 20, 2011 Hi I have written the below code to echo a table <table> <?php //start top 10 loop $sql=mysql_query("SELECT * FROM Games ORDER BY up DESC LIMIT 10"); while($row=mysql_fetch_array($sql)) { $title=$row['gametitle']; $gameid=$row['gameid']; $up=$row['up']; ?> <tr><td><a href="Reviews.php?gameid=<?php echo $gameid ?>"><?php echo $title ?></a> <td align="right"><?php echo $up ?></td> </tr> <?php //end top 10 loop } ?> </table> I want to add a new column to the table that lists them as 1 through to ten. Can anybody advise the best way to do this? Thanks Link to comment https://forums.phpfreaks.com/topic/247486-echo-1-10-in-table/ Share on other sites More sharing options...
MasterACE14 Posted September 20, 2011 Share Posted September 20, 2011 just add a counter: <table> <?php //start top 10 loop $i = 1; // counter $sql=mysql_query("SELECT * FROM Games ORDER BY up DESC LIMIT 10"); while($row=mysql_fetch_array($sql)) { $title=$row['gametitle']; $gameid=$row['gameid']; $up=$row['up']; ?> <tr><td><?php echo $i; ?></td> <tr><td><a href="Reviews.php?gameid=<?php echo $gameid ?>"><?php echo $title ?></a> <td align="right"><?php echo $up ?></td> </tr> <?php //end top 10 loop $i++; // add 1 to the counter } ?> </table> Link to comment https://forums.phpfreaks.com/topic/247486-echo-1-10-in-table/#findComment-1270886 Share on other sites More sharing options...
hoponhiggo Posted September 20, 2011 Author Share Posted September 20, 2011 Thank you. That was alot easier than i thought it would be Link to comment https://forums.phpfreaks.com/topic/247486-echo-1-10-in-table/#findComment-1270888 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.