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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.