如何计算组ID所在的所有用户

How to count all users where group id

我可以将此 $this->db->where() 与 codeigniter count_all()

一起使用吗

下面的代码正确吗?

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()用于确定特定table.
中的行数 因此,您应该使用 count_all_results() 来确定特定 query.

中的行数

你可以试试这个:

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