关于分页传参的问题
自己项目需要分页功能 如果分页需要其他查询参数的话 要if($_get['xxx']!='') $this->db->where('xxx','123');
需要这样的where条件组合
但是分页前提是要获得在当前条件下的记录数
然后创建分页链接 ,接着才是查询记录,因为之前的where被清空了 查询记录的时候又要写
if($_get['xxx']!='') $this->db->where('xxx','123');
感觉写好多重复的东西 有什么好的办法
查询条件先保存下来。 第一步,用查询条件获得 总记录数 ;第二步,用查询条件加分页获取数据。 yuzhigang5460 发表于 2015-10-14 09:25
查询条件先保存下来。 第一步,用查询条件获得 总记录数 ;第二步,用查询条件加分页获取数据。 ...
怎么保存啊
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")); 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"));
$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);
页:
[1]