AinzOoalGown Posted March 5, 2022 Share Posted March 5, 2022 Hi All, I was wondering if anyone can help me with where I have went wrong with this count: $mobGroup = $this->db->prepare("SELECT COUNT(*) AS total FROM mobs INNER JOIN locations ON MOB_group = L_mobGroup WHERE MOB_group = L_mobGroup"); $mobGroup = $mobGroup->fetch(PDO::FETCH_ASSOC); $groupTotal = $mobGroup["total"]; I am trying to count all rows in a column have have the same value between MOB_group and L_mobGround from "mobs" table and" location" table and pull the count result. So location = 1 Then and rows in mobs column "MOB_groups" = 1 it counts them and returns the value, should be 2 but its not returning any value. Thanks in advance Quote Link to comment Share on other sites More sharing options...
ags_cs4 Posted March 6, 2022 Share Posted March 6, 2022 $location_id = 1; $mobGroup = $this->db->select( "SELECT COUNT(*) AS 'total' FROM `mobs` LEFT OUTER JOIN `locations` ON (`L_mobGroup` = `MOB_group`) WHERE `L_id` = :id", [ ':id'=> $location_id ] ); $groupTotal = $mobGroup["total"]; try this at least from that what i understood 😛 1 Quote Link to comment Share on other sites More sharing options...
AinzOoalGown Posted March 6, 2022 Author Share Posted March 6, 2022 (edited) 1 hour ago, ags_cs4 said: $location_id = 1; $mobGroup = $this->db->select( "SELECT COUNT(*) AS 'total' FROM `mobs` LEFT OUTER JOIN `locations` ON (`L_mobGroup` = `MOB_group`) WHERE `L_id` = :id", [ ':id'=> $location_id ] ); $groupTotal = $mobGroup["total"]; $location_id = 1; $mobGroup = $this->db->select( "SELECT COUNT(*) AS 'total' FROM `mobs` LEFT OUTER JOIN `locations` ON (`L_mobGroup` = `MOB_group`) WHERE `L_id` = :id", [ ':id'=> $location_id ] ); $groupTotal = $mobGroup["total"]; try this at least from that what i understood 😛 Awesome thank you that worked 🙂 Really appreciate your reply and help, I was stuck on that for a few hours! Thanks again buddy Edited March 6, 2022 by AinzOoalGown 1 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.