codeigniter 使用

CodeIgniter系列 记录count和分页

对于某个表的不带条件的count,可以简单的用

$total = $this->db->count_all($table_name)

来获取,但是如果有条件,则要用count_all_results

$this->db->where('sex', 'M');

$this->db->from('user');

$total = $this->db->count_all_results();

CI的pagination库可以帮助添加分页链接,用法可以看user_guide/libraries/pagination.html

有几点需要说明。

base_url里边如果有超过2个uri_segments,则需要设置$config['uri_segment'] = base_url_segments + 1

也就是uri_segment默认是3。如果不设置的话,第一页和前一页,后一页的链接都不正确。

文章标签: user urltable 

猜你喜欢

转载自www.cnblogs.com/andydao/p/9282173.html