user4419336
user4419336

Reputation:

How to count all users where group id

Can I use this $this->db->where() with codeigniter count_all()

Have i got the code correct below?

public function getTotalUsersByGroupId( $user_group_id ) 
{
    $this->db->where('user_group_id', (int) $user_group_id);
    return $this->db->count_all($this->db->dbprefix . 'user');
}

Upvotes: 0

Views: 44

Answers (1)

PJ Bergeron
PJ Bergeron

Reputation: 2998

count_all() is used to determine the number of rows in a particular table.
So instead you should use count_all_results() which is used to determine the number of rows in a particular query.

You can try this:

public function getTotalUsersByGroupId( $user_group_id ) 
{
    $this->db->where('user_group_id', (int) $user_group_id);
    return $this->db->count_all_results('your_table');
}

Upvotes: 1

Related Questions