brown2005 Posted June 11, 2006 Share Posted June 11, 2006 i have two fieldsnamepointsi 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? Quote Link to comment https://forums.phpfreaks.com/topic/11733-ranking/ Share on other sites More sharing options...
birdie Posted June 11, 2006 Share Posted June 11, 2006 [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 :-) Quote Link to comment https://forums.phpfreaks.com/topic/11733-ranking/#findComment-44382 Share on other sites More sharing options...
Barand Posted June 12, 2006 Share Posted June 12, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/11733-ranking/#findComment-44488 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.