Jump to content

Max Score, for each game


KingOfHeart

Recommended Posts

I want to get the max score for each game (which I got working) but I need it to display the proper "name".

 

function UpdateArcade()
{
$sql = mysql_query("Select id, game, timedate, name, MAX(score) FROM HighScores Group By game");
while($row = mysql_fetch_array($sql)) {
	echo "Game: " . $row['game'] . "<br>";
	echo "Score: " . $row['MAX(score)'] . "<br>";
	echo "Time: " . $row['timedate'] . "<br>";
	echo "Name: " . $row['name'] . "<br>";
	echo "<p>";
}
}

 

One of my OutPuts.

 

Game: 3

Score: 642 < correct

Time: 20090201045121 < wrong as well

Name: Affen < wrong, he did not even make a score in this game

 

So what's wrong here?

Link to comment
https://forums.phpfreaks.com/topic/153066-max-score-for-each-game/
Share on other sites

For the time issue im guessing you're using mktime() ? Or something to give back the unix. You could do this:

function UpdateArcade() {
$sql = mysql_query("Select id, game, timedate, name, MAX(score) FROM HighScores Group By game");
while($row = mysql_fetch_array($sql)) {	
	$today = $row['timedate'];
	$time = $today['month'] . " " . $today['mday'] . ", " . $today['year'];
	$time .= " " . $today['hours'] . ":" . $today['minutes'] . ":" . $today['seconds'];

	echo "Game: " . $row['game'] . "<br>";
	echo "Score: " . $row['MAX(score)'] . "<br>";
	echo "Time: $time <br>";
	echo "Name: " . $row['name'] . "<br>";
	echo "<p>";
}
}

 

Is the max score the highest scored value by certain player? because if you're grouping by game, it's gunna group all that data and pick the Max Score obviously but it'll choose the first name.

 

Maybe you could try.

 

 $sql = mysql_query("Select * FROM HighScores ORDER BY score DESC"); 

 

This will output like:

 

GAME: UNO - SCORE 1000 - TIME: 12/3/2007 12:13:53 - NAME: Bob.

GAME: CROSS - SCORE 800 - TIME: 12/3/2007 12:13:53 - NAME: Peter

GAME: UNO - SCORE 710 - TIME: 12/3/2007 12:13:53 - NAME: Bob

 

And so fourth. I don't know if that is specifically what you're after though.

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.