AshmanSNET Posted October 8, 2007 Share Posted October 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72273-returning-highest-score/ Share on other sites More sharing options...
Rithiur Posted October 8, 2007 Share Posted October 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/72273-returning-highest-score/#findComment-364476 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.