I have a weird problem. When I run this script I get 10 records from the database but they are all exactly the same. I have no idea what I am doing wrong or how to fix it. Please help me.
I have tables AMCMS_highscores , AMCMS_users , AMCMS_games I want to look inside the AMCMS_highscores table, get the last 10 records but only where the field gameid is 1997 for example. Any help is appreciated.
$data = query("SELECT `AMCMS_highscores`.`primkey` , `AMCMS_highscores`.`gameid` , `AMCMS_highscores`.`score` , `AMCMS_users`.`username` , `AMCMS_highscores`.`status` , `AMCMS_highscores`.`userkey` , `AMCMS_games`.`primkey` , `AMCMS_games`.`gamename` FROM `AMCMS_highscores` , `AMCMS_games` , `AMCMS_users` WHERE `AMCMS_highscores`.`gameid` = '$gameid' AND `AMCMS_highscores`.`userkey` != `AMCMS_users`.`userkey` AND `AMCMS_highscores`.`gameid` = `AMCMS_games`.`primkey` AND `AMCMS_highscores`.`status`= 'approved' ORDER by `AMCMS_highscores`.`primkey` DESC LIMIT 0, 10");
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data )) {
Print "<tr>";
Print "<th>Score:</th> <td>".$info['score'] . "</td> ";
Print "<th>ID:</th> <td>".$info['userkey'] . " </td></tr>"; }
Print "</table>";
Here's a formatted version of the query:
SELECT
`AMCMS_highscores`.`primkey` , `AMCMS_highscores`.`gameid` ,
`AMCMS_highscores`.`score` , `AMCMS_users`.`username` ,
`AMCMS_highscores`.`status` , `AMCMS_highscores`.`userkey` ,
`AMCMS_games`.`primkey` , `AMCMS_games`.`gamename`
FROM `AMCMS_highscores` , `AMCMS_games` , `AMCMS_users`
WHERE `AMCMS_highscores`.`gameid` = '$gameid'
AND `AMCMS_highscores`.`userkey` != `AMCMS_users`.`userkey`
AND `AMCMS_highscores`.`gameid` = `AMCMS_games`.`primkey`
AND `AMCMS_highscores`.`status`= 'approved'
ORDER by `AMCMS_highscores`.`primkey` DESC
LIMIT 0, 10