selliott Posted January 20, 2009 Share Posted January 20, 2009 Hello, I put together some code that displays ranks, but if two people have the same amount of points (tied) I want them to have the same rank...then the next would skip a number. For example, like this Rank Name Points 1 Joe 105 2 John 101 2 Shawn 101 4 Sam 100 Right now, my code would just list the rankings for these members as 1,2,3,4 Here's my current code: <?php echo '<table cellpadding="3" cellspacing="0" style="width:100%;"> <tr> <td>Rank</td><td>Driver</td><td>Points</td> </tr>'; $rank = 1; while($r = mysql_fetch_array($Points)){ echo ' <tr> <td class="topline">' . $rank . '</td> <td class="topline">' . $r['Name'] . '</td> <td class="topline">' . $r['Points'] . '</td> </tr>'; $rank++; } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/141547-solved-rank-by-points-issue/ Share on other sites More sharing options...
.josh Posted January 20, 2009 Share Posted January 20, 2009 <?php /*** begin mock db select ***/ for ($x = 1; $x <=20; $x++) { $array[] = rand(100,110); } sort($array); /*** end mock db select *****/ $rank = 0; foreach($array as $score) { $r = ($score == $oldScore)? $rank : ++$rank; echo $r . " " . $score . "<br/>"; $oldScore = $score; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141547-solved-rank-by-points-issue/#findComment-740926 Share on other sites More sharing options...
selliott Posted January 20, 2009 Author Share Posted January 20, 2009 <?php /*** begin mock db select ***/ for ($x = 1; $x <=20; $x++) { $array[] = rand(100,110); } sort($array); /*** end mock db select *****/ $rank = 0; foreach($array as $score) { $r = ($score == $oldScore)? $rank : ++$rank; echo $r . " " . $score . "<br/>"; $oldScore = $score; } ?> Thanks for the reply. What would I put in place of $array to get this to work with my connection? This is my SELECT statement: $Points = mysql_query("SELECT ID, Name, Points FROM tq_Points ORDER BY Points DESC", $connection) or die("error querying database"); Quote Link to comment https://forums.phpfreaks.com/topic/141547-solved-rank-by-points-issue/#findComment-740942 Share on other sites More sharing options...
.josh Posted January 20, 2009 Share Posted January 20, 2009 you would query your db and use your while loop instead of the foreach loop and check your current row's score against your previous row's score. Come on man I showed you how to pee in the toilet; you want me to unzip your fly and hold your willy too? Quote Link to comment https://forums.phpfreaks.com/topic/141547-solved-rank-by-points-issue/#findComment-740951 Share on other sites More sharing options...
selliott Posted January 20, 2009 Author Share Posted January 20, 2009 you want me to unzip your fly and hold your willy too? Classy. Quote Link to comment https://forums.phpfreaks.com/topic/141547-solved-rank-by-points-issue/#findComment-740968 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.