Q:

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');
}

A:

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');
}

