Jump to content
MakeWebGames

Troubles with Query


Sim

Recommended Posts

My query returns an empty result in phpMyAdmin which it is supposed to do, but when I get the results in GL, it's returning a record. Any ideas?

  $sidekick = $this->db->prepare("
  SELECT
    SK_id AS 'id',
    SK_name As 'name',
    SK_fType AS 'fileType',
    SK_level AS 'level',
    SK_guard AS 'guard',
    SK_attack AS 'attack'
  FROM 
    sidekicks
    JOIN
  userStats ON(US_sidekickID = SK_id)
  WHERE
  US_id=:id
  ");

    $sidekick->bindParam(":id", $userID);
    $sidekick->execute();
    $test = $sidekick->fetch(PDO::FETCH_ASSOC);
    debug (var_dump($test));

 

array(6) { ["id"]=> string(1) "1" ["name"]=> string(12) "Gangster Wan" ["fileType"]=> string(4) ".png" ["level"]=> string(1) "1" ["guard"]=> string(2) "45" ["attack"]=> string(2) "23" }

 

Screenshot_20200914_102519.thumb.jpg.0d5c1b2b3806ed0a3ab5caea94b7e4e3.jpg

Link to comment
Share on other sites

I think what you need is a left join query, try something like this;

```

$sidekick = $this->db->prepare("
 SELECT sk.`id`, sk.`name`, sk.`fileType`, sk.`level`, sk.`guard`,  sk.`attack`, us.`sidekickID`
FROM  `sidekicks` sk
LEFT JOIN `userStats` us ON sk.`id` = us.`sidekickID`

```

Edited by Spydre452
Link to comment
Share on other sites

Yoo know if you are referencing your tables like you did, yoo do not need a join statement.

You could do

WHERE sk.SK_id = us.US_sidekick

 

The same query in question comes back with no results in my screenshot, but in the coffee shows results which is confusing me as this is the first time I've ever managed to do that.

Edited by Sim
Link to comment
Share on other sites

1 hour ago, Sim said:

Yoo know if you are referencing your tables like you did, yoo do not need a join statement.

You could do

WHERE sk.SK_id = us.US_sidekick

 

The same query in question comes back with no results in my screenshot, but in the coffee shows results which is confusing me as this is the first time I've ever managed to do that.

Nice okay, I didn't know that, now I've no idea - sorry

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...