Jump to content

Returning highest score


AshmanSNET

Recommended Posts

G'day,

I've been able to get the highest score from my table, however in some instances mysql_num_rows returns > 1, which is fine, just means two rows have the same score. I need to be able to now work out who has the highest VoteCount of all the results I got back from the highest score check. I need this because by the end, I only want the result of the Map with the highest score with the most votes (Yes it's a map server I'm making)

 

This is my code so far:

//Find highest score value from Mapserver table
$iGetHighest= mysql_query("SELECT max(Score) as iHighestScore from Mapserver");  
$iRow = mysql_fetch_array( $iGetHighest );
$iHighestScore = $iRow['iHighestScore'];

//Find the map(s) who has a score equal to $iHighestScore
$iResult= mysql_query("SELECT * FROM Mapserver WHERE Score=$iHighestScore");  
$iReturned = mysql_num_rows( $iResult );

if($iReturned > 1)
{
     //Returned more than one map with score = $iHighestScore
     for($i = 0; $i < $iReturned; $i++)
     {
          $row = mysql_fetch_assoc($iResult);
          $sMapName = $row['Name'];
          $sVotes = $row['VoteCount'];
          //Problem lies here, how do I get the highest VoteCount from 
          //all results returned from highest score check?!
     }
}

 

Hope that was clear enough to understand :)

 

Thanks

 

Ashman

Link to comment
https://forums.phpfreaks.com/topic/72273-returning-highest-score/
Share on other sites

Here's a simple query, you could use to get the highest scoring field without any addinational querys:

 

SELECT * FROM Mapserver ORDER BY Score DESC, VoteCount DESC LIMIT 1

 

That'll get you only one highest row, first sorting by the Score and then by the VoteCount, if they happen to have the same Score.

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.