简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM