jdubwelch Posted March 16, 2007 Share Posted March 16, 2007 I have a table full of players with their number of points. I want to rank them, but if they're are more than one I want to count those, and set a ranking to them. For example: let's say player A has 10pts, B 8pts, C 8pts, D 6pts, E 6pts, F 6pts, and G 2pts. I want them to be ranked: #1 - A [ 10 pts] #2 - B [ 8 pts] - C [ 8 pts] #3 - D [ 6 pts] - E [ 6 pts] - F [ 6 pts] #4 - G [ 2 pts] how do i do that? here's the code that just makes an ordered list of the players and points: $query = "SELECT users . first_name , users . last_name , tourney_stats . totpts FROM `tourney_stats` , `users` WHERE users . user_id =tourney_stats . user_id ORDER BY `tourney_stats` . `totpts` DESC LIMIT 9"; $db_query = mysql_query ($query) or die (mysql_error()); echo "<ol>\n"; while ($row = mysql_fetch_array ($db_query)) { $first = $first = $row['first_name']; $first = substr($first, 0, 2); $pts = $row[totpts]; echo "<li>$first. $row[last_name] [ $pts ]</li>\n"; } echo "</ol>\n"; Link to comment https://forums.phpfreaks.com/topic/43014-counting-consective-from-db/ Share on other sites More sharing options...
Psycho Posted March 16, 2007 Share Posted March 16, 2007 Try this: <?php $query = "SELECT users . first_name , users . last_name , tourney_stats . totpts FROM `tourney_stats` , `users` WHERE users . user_id =tourney_stats . user_id ORDER BY `tourney_stats` . `totpts` DESC LIMIT 9"; $db_query = mysql_query ($query) or die (mysql_error()); echo "<ol>\n"; $last_points = ''; while ($row = mysql_fetch_array ($db_query)) { $first = substr($row['first_name'], 0, 2); $pts = $row[totpts]; if ($last_points != $pts) { if ($last_points != '') { echo "</li>\n"; } echo "<li>"; $last_points = $pts; } echo "$first . $row[last_name] [ $pts ]<br>\n"; } echo "</li>\n"; echo "</ol>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/43014-counting-consective-from-db/#findComment-208924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.