Jump to content

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.

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.