Sim Posted September 14, 2020 Share Posted September 14, 2020 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" } Quote Link to comment Share on other sites More sharing options...
Spydre452 Posted September 14, 2020 Share Posted September 14, 2020 (edited) 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 September 14, 2020 by Spydre452 Quote Link to comment Share on other sites More sharing options...
Sim Posted September 14, 2020 Author Share Posted September 14, 2020 (edited) 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 September 14, 2020 by Sim Quote Link to comment Share on other sites More sharing options...
Spydre452 Posted September 14, 2020 Share Posted September 14, 2020 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.