Jump to content

php sql showing a table rows rank by a column????


robbins

Recommended Posts

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!
[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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.