Joh*_*nny 10 activerecord codeigniter
我与最新的工作codeIgniter释放出来,而且我也有工作jquery datatables,从datatables.net
我写过这个函数:https://gist.github.com/4478424 哪个,工作正常.除非我使用文本框输入内容进行过滤.过滤器本身会发生,但我的计数完全关闭.
我尝试$res = $this->db->count_all_results()在我之前添加get,并且它会停止工作.我需要完成什么,if ($data['sSearch'] != '')然后利用整个查询,而不用limit查看搜索过滤器存在多少总行数.
如果您需要在我的要点中看到除了什么之外的任何其他代码,请询问并继续发布.
Bre*_*dan 23
$this->db->count_all_results()替换$this->db->get()数据库调用.
你可以调用IE count_all_results()或者get(),或者不是两者.
您需要执行两个单独的活动记录呼叫.一个用于分配结果#,另一个用于获取实际结果.
伯爵这样的东西:
$this->db->select('id');
$this->db->from('table');
$this->db->where($your_conditions);
$num_results = $this->db->count_all_results();
对于实际查询(您应该已经拥有):
$this->db->select($your_columns);
$this->db->from('table');
$this->db->where($your_conditions);
$this->db->limit($limit);
$query = $this->db->get();
您是否阅读过http://ellislab.com/codeigniter/user-guide/database/active_record.html#caching?
我看到你正试图做一些分页,你需要"真正的"总结果并同时限制.
这是我在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.
我在没有测试的情况下键入了上面的代码,但它应该是这样的.我在所有项目中都这样做.
小智 5
您实际上不必拥有 from ,您可以将表名称包含在 count_all_results 中,如下所示。
$this->db->count_all_results('table_name');