codeigniter count_all_results [英] codeigniter count_all_results

查看:1140
本文介绍了codeigniter count_all_results的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新的 codeIgniter 发布,我还使用 jquery datatables 从 datatables.net



我写了这个函数: https://gist.github.com/4478424 其中,工作正常。



我试图在 $ res = $ this-> db-> count_all_results()之前的 get ,并停止get。我需要完成, if($ data ['sSearch']!='')然后利用整个查询没有 code>以查看存在搜索过滤器的总行数。



如果您需要查看除了gist中的任何其他代码,

解决方案

$ 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();


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

I've written this function: https://gist.github.com/4478424 which, as is works fine. Except when I filter by using the text box typing something in. The filter itself happens, but my count is completely off.

I tried to add in $res = $this->db->count_all_results() before my get, and it stops the get from working at all. What I need to accomplish, if ($data['sSearch'] != '') then to utilize the entire query without the limit to see how many total rows with the search filter exists.

If you need to see any other code other than whats in my gist, just ask and I will go ahead and post it.

解决方案

$this->db->count_all_results() replaces $this->db->get() in a database call.

I.E. you can call either count_all_results() or get(), but not both.

You need to do two seperate active record calls. One to assign the results #, and one to get the actual results.

Something like this for the count:

$this->db->select('id');
$this->db->from('table');
$this->db->where($your_conditions);
$num_results = $this->db->count_all_results();

And for the actual query (which you should already have):

$this->db->select($your_columns);
$this->db->from('table');
$this->db->where($your_conditions);
$this->db->limit($limit);
$query = $this->db->get();

这篇关于codeigniter count_all_results的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆