simonp Posted November 24, 2007 Share Posted November 24, 2007 Hi folks, I'm using: $sql = "SELECT * from $myTable ORDER BY `points` DESC LIMIT 5"; in a whileloop to display the top five scorers but would like to put their position next to the results (eg, 1, 2, 3, 4 and 5) Is there an easy way to do this? Cheers Simon Link to comment https://forums.phpfreaks.com/topic/78674-solved-php-mysql-order-results/ Share on other sites More sharing options...
LordOrange Posted November 24, 2007 Share Posted November 24, 2007 I would define a variable at the beginning of the loop and set it to add on to that variable every loop and then just print it where you want it Link to comment https://forums.phpfreaks.com/topic/78674-solved-php-mysql-order-results/#findComment-398109 Share on other sites More sharing options...
hostfreak Posted November 24, 2007 Share Posted November 24, 2007 Try: <?php //sql //result $i = 1; while ($row= mysql_fetch_assoc($result)) { echo $i . ' ' . $row['column']; $i++; } ?> edit: which is basically doing what LordOrange said Link to comment https://forums.phpfreaks.com/topic/78674-solved-php-mysql-order-results/#findComment-398111 Share on other sites More sharing options...
simonp Posted November 24, 2007 Author Share Posted November 24, 2007 Thanks LordOrange and hostfreak - worked a treat! Cheers Simon Link to comment https://forums.phpfreaks.com/topic/78674-solved-php-mysql-order-results/#findComment-398283 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.