robbins Posted January 8, 2007 Share Posted January 8, 2007 how can i use php to query a mysql database and like show what rank something is via ... lets say the points column....so like it would say this user is ranked: ## and ## would be the number sorted by points in their user table.....how can i do this?? i'm guessin its got something to do with sorting... but idk... please help. thanks! Link to comment https://forums.phpfreaks.com/topic/33272-php-sql-showing-a-table-rows-rank-by-a-column/ Share on other sites More sharing options...
trq Posted January 8, 2007 Share Posted January 8, 2007 [code]<?php // connect to db if ($result = mysql_query("SELECT uname FROM users ORDER BY points DESC")) { if (mysql_num_rows($result) > 0) { $rank = 1; while ($row = mysql_fetch_assoc($result)) { echo $row['uname'].' is ranked number '.$rank.'<br />'; $rank++; } } }?>[/code] Link to comment https://forums.phpfreaks.com/topic/33272-php-sql-showing-a-table-rows-rank-by-a-column/#findComment-155405 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.