j897011372 发表于 2017-4-13 10:36:56

CI分页total_rows支取一些值

我在我的页面代码是这样的$config['total_rows'] = $this->db->count_all_results('exam_guanli');,这样统计的是数据库中所有的数据,请问如果我经过一个方法查询出来的数据是两条甚至更多,我先想用这个数量做个分页,而不是所有,应该用用什么方法呢

Hex 发表于 2017-4-13 10:54:36

仔细看这里 http://codeigniter.org.cn/user_guide/database/query_builder.html#id6 ,是可以给一个 where 条件的。

j897011372 发表于 2017-4-13 11:17:54

Hex 发表于 2017-4-13 10:54
仔细看这里 http://codeigniter.org.cn/user_guide/database/query_builder.html#id6 ,是可以给一个 where ...

他这里where怎么使用啊$config['total_rows'] = $this->db->where(..)->from();嘛,这样不就没有count_all_results,count_all_results()里面第二值还得是FLASE

Hex 发表于 2017-4-13 14:25:46

j897011372 发表于 2017-4-13 11:17
他这里where怎么使用啊$config['total_rows'] = $this->db->where(..)->from();嘛,这样不就没有count_a ...

这里不是有一个例子么?

$this->db->where('title', 'match');
$this->db->from('my_table');
echo $this->db->count_all_results(); // Produces an integer, like 17
页: [1]
查看完整版本: CI分页total_rows支取一些值