widget Posted May 29, 2011 Share Posted May 29, 2011 Hi all I have some code that displays the high scores for a game. Unfortunately, if a user has more than 1 high score in the table all scores for that user are displayed. I would like to only display the highest score per user. My Current Code $sql_query = sprintf("SELECT * FROM `highscores` WHERE `gameID` = '106' ORDER BY `score` DESC"); //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { //output as long as there are still available fields while($row = mysql_fetch_row($result)) { echo ("$row[3] Scored :$row[5] <br>"); } } //if no fields exist else { echo "no values in the database"; } mysql_close($con); OutPut User1 300 User1 298 User 2 297 User1 296 User3 295 User2 290 I would like the output to be User1 300 User 2 297 User3 295 Any help is much appreciated Link to comment https://forums.phpfreaks.com/topic/237763-displaying-high-scores-highest-score-per-user/ Share on other sites More sharing options...
widget Posted May 29, 2011 Author Share Posted May 29, 2011 I may have fixed it. $sql_query = sprintf("SELECT * FROM `highscores` WHERE `gameID` = '106' GROUP BY 'username' ORDER BY `score` DESC"); Link to comment https://forums.phpfreaks.com/topic/237763-displaying-high-scores-highest-score-per-user/#findComment-1221829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.