Jump to content
MakeWebGames

Recommended Posts

Posted

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

Posted
$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 😛 

  • Thanks 1
Posted (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 by AinzOoalGown
  • Like 1

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...