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

  • Home
  • SEARCH
  • 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 9181827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:24:48+00:00 2026-06-17T18:24:48+00:00

I have a problem with my JSON respons. In my mysql database I have

  • 0

I have a problem with my JSON respons. In my mysql database I have two tables: Users and Games. When I try to get all the games from 1 user, I get those games in my respons but * the amount of different users I have in my Users table. So if I want all the games from a user with id 8, and that are for example 3 games, I get those games but times the amount of unique users I have, let’s say 9. So the query returns 27 games (9 * 3 same games). What is it that I’m doing wrong here.

 $pm_id = $_POST["pm_id"];
 $pm_pass = $_POST["pm_pass"];
 $pm_timestamp = $_POST["pm_timestamp"];

try {
     $dbconn = 'mysql:host=' . DBHOST . ';dbname=' . DBDATA;
     $db = new PDO($dbconn, DBUSER, DBPASS);
 } catch (PDOException $e) {
     echo 'Connection failed: ' . $e->getMessage();
 }

 $statement = $db->prepare('SELECT * FROM users WHERE user_id = :id AND password =      :pass');
 $statement->execute(array(':id' => $pm_id, ':pass' => $pm_pass));
 $statement->setFetchMode(PDO::FETCH_ASSOC);

 $row = $statement->fetch();
     if($row['timestamp'] == $pm_timestamp){
         #no sync necessary
         echo json_encode("no sync needed");
     }else{
         #start sync
         $games = array();
         $statement_getAllGames = $db->prepare('SELECT game.game_id, game.user_id,       game.name, game.buyin, game.result, game.startDate, game.endDate, game.location,      game.isTournament, game.participants, game.endposition, game.comment, game.blinds,      game.pause,
         game.visibility, users.timestamp FROM game, users WHERE game.user_id = :id AND    game.timestamp > :timestamp');
         $statement_getAllGames->execute(array(':id' => $pm_id, ':timestamp' =>   $pm_timestamp));

         while($row = $statement_getAllGames->fetch(PDO::FETCH_ASSOC)){
             $games[] = array('game'=>$row);
         }
         echo json_encode(array('games'=>$games));

 };

If it’s helpful I can add the structure of my tables.

  • 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-06-17T18:24:49+00:00Added an answer on June 17, 2026 at 6:24 pm
    FROM game, users
    

    You are missing the join condition game.user_id = user.user_id. You could add this to your WHERE clause, or you could use the newer SQL-92 join syntax (see INNER JOIN ON vs WHERE clause):

    FROM game INNER JOIN users ON game.user_id = user.user_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem when try to get and parse a remote JSON. require
I have a problem with Json formating returned from .ASMX I need to return
I have a problem with deserializing JSON data from an external REST service. Depending
I Have two problem in this Case : I want to pass a JSON
I have a problem returning/processing JSON data while calling $.get() function. Here's the code:
Have such problem: when use spring security 3, try to ask resource (via GET)
i try parse json, but i have problem, when i runing my app, i
I have this problem : I'm checking user email in controller and sending json
i have the following JSON response from google maps. I've given two postcodes as
I have a problem sending JSON Array to Servle t from Android. But I

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.