Jump to content

Displaying High Scores - Highest score per user


widget

Recommended Posts

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

 

Archived

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

×
×
  • Create New...

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.