Jump to content

ranking


brown2005

Recommended Posts

[code]
$sql = "SELECT * FROM table ORDER BY points DESC";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query))
{
$points = $row['points'];
$person = $row['person'];
if($lastpersonspoints == $points)
{
$rank = $lastpersonsrank;
}
else
{
$rank = ""; //not sure how u are ordering this..
}
$lastpersonsrank = $rank;
$lastpersonspoints = $points;
}
[/code]

That was completely off the top of my head so its probably got loads of errors. hope it gives u an idea of how u can do it :-)
Link to comment
https://forums.phpfreaks.com/topic/11733-ranking/#findComment-44382
Share on other sites

try
[code]$pos= $rank = 1;
$prev = 0;
$sql = "SELECT name, points FROM table ORDER BY points DESC";
$query = mysql_query($sql);
while(list($name, $pts) = mysql_fetch_row($query))    {
     $rank = $pts==$prev ? $rank : $pos;
     echo "$rank $n $v <br>";
     $pos++;
     $prev = $pts;
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/11733-ranking/#findComment-44488
Share on other sites

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.