用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1942|回复: 5
收起左侧

[分页] 关于分页传参的问题

[复制链接]
发表于 2015-10-14 09:22:00 | 显示全部楼层 |阅读模式
自己项目需要分页功能 如果分页需要其他查询参数的话 要
if($_get['xxx']!='') $this->db->where('xxx','123');
需要这样的where条件组合

但是分页前提是要获得在当前条件下的记录数

然后创建分页链接 ,接着才是查询记录,因为之前的where被清空了 查询记录的时候又要写
if($_get['xxx']!='') $this->db->where('xxx','123');

感觉写好多重复的东西 有什么好的办法
发表于 2015-10-14 09:25:19 | 显示全部楼层
查询条件先保存下来。 第一步,用查询条件获得 总记录数 ;第二步,用查询条件加分页获取数据。
 楼主| 发表于 2015-10-14 09:26:07 | 显示全部楼层
yuzhigang5460 发表于 2015-10-14 09:25
查询条件先保存下来。 第一步,用查询条件获得 总记录数 ;第二步,用查询条件加分页获取数据。 ...

怎么保存啊
 楼主| 发表于 2015-10-14 09:26:27 | 显示全部楼层
if( !empty($sname) ) $this->db->where('sname',$sname);
if( !empty($start) ) $this->db->where('loginTime >',strtotime($start));
if( !empty($end) ) $this->db->where('loginTime <',strtotime($end." 23:59:59"));
发表于 2015-10-14 11:21:15 | 显示全部楼层
huihui0103 发表于 2015-10-14 09:26
if( !empty($sname) ) $this->db->where('sname',$sname);
if( !empty($start) ) $this->db->where('loginT ...

if( !empty($sname) ) $this->db->where('sname',$sname);
if( !empty($start) ) $this->db->where('loginTime >',strtotime($start));
if( !empty($end) ) $this->db->where('loginTime <',strtotime($end." 23:59:59"));
PHP复制代码
$where = array();
$sname && $where['sname'] = $sname;
$start && $where['loginTime >  '] = strtotime($start);
$end && $where['loginTime < '] = strtotime($end.'23:59:59');
$count = $this->db->where($where)->count_all_results();
$records = $this->db->where($where)->order_by('id', 'desc')->limit( 20);
 
复制代码


点评

很不错  发表于 2015-10-15 21:49

本版积分规则