求一个在多搜索条件页面做分页的思路
做一个高级查询,同时可查询的字段可能会有八九个要什么方式解决分页问题会比较靠谱呢?
请做有类似经验的朋友指点一下。谢谢了。
{:soso_e151:} 分页和你查询的条件貌似木有啥关系吧 。。 smilecc123 发表于 2014-4-15 12:56
分页和你查询的条件貌似木有啥关系吧 。。
下一页不是要把当前参数传过去么?
* 日志
*/
class Log extends MY_Controller{
//用户发布日志
public function list_log(){
$type =$this->uri->segment(3); //url第三个参数 项目id
$start=$this->uri->segment(4); //url第四个参数 开始时间
$end=$this->uri->segment(5); //url第五个参数 结束时间
$flag =$this->uri->segment(6); //url第六个参数 发布状态
$uid=$this->session->userdata('uid')?$this->session->userdata('uid'):0;
$this->load->model('publish_log_model','plog');
$this->config->set_item('url_suffix', ''); //后台设置后缀为空,否则分页出错
$this->load->library('pagination'); //载入分页类
$perPage = 15;
//配置项设置
$config['base_url'] = site_url("log/list_log/$type/$start/$end/$flag");
$config['total_rows'] = count($this->plog->user_log($uid,$type,$start,$end,$flag));
$config['per_page'] = $perPage;
$config['uri_segment'] = 7; //url第七个参数 分页使用
$config['first_link'] = '第一页';
$config['prev_link'] = '上一页';
$config['next_link'] = '下一页';
$config['last_link'] = '最后一页';
$this->pagination->initialize($config);
//生成分布
$data['links'] = $this->pagination->create_links();
$offset = $this->uri->segment(7); //url第七个参数 分页使用
$this->db->limit($perPage, $offset);
$data['llist']=$this->plog->user_log($uid,$type,$start,$end,$flag);
//把筛选条件赋给模板
$data['type'] =$type;
$data['start']=$start;
$data['end']=$end;
$data['flag'] =$flag;
$plist=$this->db->get('fmb_project')->result_array();
$data['plist']=$plist;
$this->load->view('list_log',$data);
}
} 上面是控制器,下面是模型方法
class Publish_log_model extends CI_Model{
/**
* 查询该用户发布日志
* @param unknown_type $uid
* @return unknown
*/
public function user_log($uid,$type,$start,$end,$flag){
//$sql="select * from axxxx";
$this->db->select('project.pname,publish_log.publish_time,publish_log.publish_desc,publish_log.flag,publish_log.snapshot_addr,user.name,publish_log.is_success');
$this->db->from('publish_log');
if($uid!='all'){
$this->db->where(array('publish_log.uid'=>$uid));
}
if($type!='all'){
$this->db->where(array('project.pid'=>$type));
}
if($flag!='all'){
$this->db->where(array('publish_log.flag'=>$flag));
}
if($start!=0 && $end !=0){
$start=strtotime($start);
$end=strtotime($end);
$this->db->where(array('publish_log.publish_time >='=>$start));
$this->db->where(array('publish_log.publish_time <'=>$end));
}
$this->db->join('project','publish_log.pid=project.pid','left');
$this->db->join('user','publish_log.uid=user.uid','left');
$this->db->order_by('id','desc');
$res=$this->db->get()->result_array();
//echo $this->db->last_query();
return $res;
}
} 小刘 发表于 2014-4-18 15:43
上面是控制器,下面是模型方法
class Publish_log_model extends CI_Model{
多谢。
这种方案如果其中一个字段没有参数就路径就会很奇怪,是不?
askswin 发表于 2014-4-21 12:48
多谢。
这种方案如果其中一个字段没有参数就路径就会很奇怪,是不?
没有参数可以用 all代替,判断是all的时候,就认为是没有任何参数的,只是占一个位而已。
小刘 发表于 2014-4-22 18:26
没有参数可以用 all代替,判断是all的时候,就认为是没有任何参数的,只是占一个位而已。
...
多谢提点!!
页:
[1]