Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 968115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:25:40+00:00 2026-05-16T02:25:40+00:00

I have a weird problem. When I run this script I get 10 records

  • 0

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

OOPS, i didnt mean to copy that but i did by accident.
When its with “=” sign (highscores.userkey = users.userkey) i get empty query so that didnt fix it 🙁

I hope this query would be easier to understand 🙂

SELECT highscores.primkey, highscores.gameid, highscores.score, users.username,
highscores.status, highscores.userkey, games.primkey, games.gamename 

FROM AMCMS_highscores AS highscores, AMCMS_games as games, AMCMS_users as users

WHERE highscores.gameid = '$gameid' AND
      highscores.status = 'approved'

ORDER by highscores.primkey DESC LIMIT 0, 10

Here is the result:

http://www.gamesorbiter.com/FB_app/play.php?gameid=1997
(under the game)

Btw, how do you code your query when you post it ? I clicked the code button and only the first line of the code got coded.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:25:40+00:00Added an answer on May 16, 2026 at 2:25 am

    If you are trying to select records from AMCMS_users for which there are no matching row in AMCMS_highscores, then you need to do a LEFT JOIN, and test for NULL values in the joined table. Here’s an extract from JOIN Syntax:

    If there is no matching row for the
    right table in the ON or USING
    part in a LEFT JOIN, a row with all
    columns set to NULL is used for the
    right table. You can use this fact to
    find rows in a table that have no
    counterpart in another table:

    Your query would therefore look more like this:

    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`
    LEFT JOIN `AMCMS_users`
        ON `AMCMS_highscores`.`userkey` = `AMCMS_users`.`userkey`
    JOIN `AMCMS_games`
        ON `AMCMS_highscores`.`gameid` = `AMCMS_games`.`primkey`
    WHERE `AMCMS_highscores`.`gameid` = '$gameid'
    AND `AMCMS_highscores`.`status`= 'approved'
    AND `AMCMS_users`.`userkey` = NULL
    ORDER by `AMCMS_highscores`.`primkey` DESC
    LIMIT 0, 10;
    

    Ignoring the other conditions for a moment, your query is looking at every row in AMCMS_highscores, and joining it to every row in AMCMS_highscores where AMCMS_highscores.userkey is not equal to AMCMS_users.userkey. This will produce a lot of matching rows. To see what is happening, remove the LIMIT clause from your query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this weird problem in java when trying to fetch records from MYSql
I have a weird problem. I create this window, but its blank until i
I have a weird, annoying problem with Python 2.6. I'm trying to run this
This is kind of a weird problem, but I have to create a search
I have a weird problem where I cannot run aapt from an sbt command
I have weird problem with this code: if I run it like shown below
I have run into a weird problem. This code returns None instead of True,
Hi I have run into a very weird problem. I have a basic chrome
I'm fairly new to using MSSQL and have run into a weird problem. Given
I have this weird problem with setting up cookies with PHP. Everything worked fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.