Search code examples
phpmysqlcodeignitergroup-bycount

select count(*) with group_by in Codeigniter


I have a library That generates a CRUD with pagination using mysql and created a query with group_by, but the $ this-> db-> count_all_results () is not counted correctly.

I made an adjustment by changing the function of the CodeIgniter for an alternative, using the previous select

select count (*) from ('. $ this-> db-> _compile_select ().') x'

Anyone have other suggestions?


Solution

  • You must specify other params after the count_all() method.

    Look this:

    $this->db->group_by('my_table_col');
    $total = $this->db->count_all('my_table');