Jump to content

Archived

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

brown2005

ranking

Recommended Posts

i have two fields

name
points

i want to create a ranking on the points DESC, but if someone has the same points as someone else i want them to be the same rank.

any help please?

Share this post


Link to post
Share on other sites
[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 :-)

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.