codeigniter count_all_results

后端 未结 7 1774
眼角桃花
眼角桃花 2021-02-14 03:37

I\'m working with the latest codeIgniter released, and i\'m also working with jquery datatables from datatables.net

I

相关标签:
7条回答
  • 2021-02-14 04:08

    Have you read up on https://www.codeigniter.com/userguide2/database/active_record.html#caching ?

    I see you are trying to do some pagination where you need the "real" total results and at the same time limiting.

    This is my practice in most of my codes I do in CI.

    
        $this->db->start_cache();
    
        // All your conditions without limit
        $this->db->from();
        $this->db->where(); // and etc...
        $this->db->stop_cache();
    
        $total_rows = $this->db->count_all_results(); // This will get the real total rows
    
        // Limit the rows now so to return per page result
        $this->db->limit($per_page, $offset);
        $result = $this->db->get();
    
        return array(
            'total_rows' => $total_rows,
            'result'     => $result,
        ); // Return this back to the controller.
    
    

    I typed the codes above without testing but it should work something like this. I do this in all of my projects.

    0 讨论(0)
提交回复
热议问题