Okay, I am fairly sure that I have gone about this in the absolutely wrong most convoluted way, but... I need to create a list of the top five players for a game (username and score).
There are four tables which house the scores for four different games (game1, game2, etc) and in each table are multiple users with scores for each time they're tried to play the game.
I know how to SUM the user's scores in one table, no problem. I have no idea how to SUM all the player scores across all four tables then pull out the top 5. I've got some code (below) but it is doing strange things because, well, I've written strange statements.
Can anyone help? I am beyond the point of frustration.
Thanks
<?php require_once('Connections/user_auth.php'); ?>
<?php
session_start();
mysql_select_db($database_user_auth, $user_auth);
$query_rshighscore = "SELECT tbl_game1.username, tbl_game2.username, tbl_game3.username, tbl_game4.username, SUM(tbl_game1.userscore), SUM(tbl_game2.userscore), SUM(tbl_game3.userscore), SUM(tbl_game4.userscore) AS highscore FROM tbl_game1, tbl_game2, tbl_game3, tbl_game4 GROUP BY tbl_game1.username, tbl_game2.username, tbl_game3.username, tbl_game4.username ORDER BY highscore ASC LIMIT 5";
$rshighscore = mysql_query($query_rshighscore, $user_auth) or die(mysql_error());
$row_rshighscore = mysql_fetch_assoc($rshighscore);
$totalRows_rshighscore = mysql_num_rows($rshighscore);
?>
<?php do { ?>
<?php echo $row_rshighscore['username']; ?>
<?php echo $row_rshighscore['SUM(tbl_game1.userscore)'];
<?php } while ($row_rshighscore = mysql_fetch_assoc($rshighscore)); ?>