We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Count and Group By Query

Development and Programming

kmgkid's avatar
kmgkid
50 posts
14 years ago
kmgkid's avatar kmgkid

I’m trying to count all the entries for exp_clicks and group them by their entry id, but cant get it. any help would be appreciated.

I’ve tried, $this->EE->db->count_all(‘exp_clicks’, ‘entry_id’); $this->EE->db->count_all(‘exp_clicks’, $this->EE->db->group_by(‘entry_id’));

Here is the query statement

SELECT entry_id, COUNT(*) as “totalclicks” FROM exp_clicks GROUP BY entry_id

thanks

       
Parse19's avatar
Parse19
44 posts
14 years ago
Parse19's avatar Parse19

Try:

$this->EE->db->select("entry_id, COUNT(*) as totalclicks");
$this->EE->db->group_by('entry_id');
$this->EE->db->get('clicks');
       
Parse19's avatar
Parse19
44 posts
14 years ago
Parse19's avatar Parse19

One note: you don’t need to use ‘exp_’ in Active Record calls. EE will add those based on your current install.

       
kmgkid's avatar
kmgkid
50 posts
14 years ago
kmgkid's avatar kmgkid

perfect. thanks

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.