codeigniter实现get分页的方法

 更新时间:2015年07月10日 09:20:31   作者:mckee  
这篇文章主要介绍了codeigniter实现get分页的方法,涉及使用codeigniter框架查询数据量及针对结果集进行get方法分页的相关技巧,非常简单实用,需要的朋友可以参考下

本文实例讲述了codeigniter实现get分页的方法。分享给大家供大家参考。具体实现方法如下:

public function project_search(){
  $this->load->library('pagination');
  $this->load->model('depart_mdl');
  //获取搜索需要的信息
  $data = $this->get_project_data();
  $get_data = $this->input->get();
  $data = array_merge($data,$get_data);
  //get分页配置
  $name = $get_data['name'];
  $username = $get_data['username'];
  $budget = $get_data['budget'];
  $type = $get_data['type'];
  $posttime_start = $get_data['posttime_start'];
  $posttime_end = $get_data['posttime_end'];
  $purchase_type = $get_data['purchase_type'];
  $depart_code = $get_data['depart_code'];
  $project_status = $get_data['project_status'];
  $bidder_way = $get_data['bidder_way'];
  $suffix = "?name=$name&username=$username&budget=$budget&type=$type&posttime_start=$posttime_start&posttime_end=$posttime_end&purchase_type=$purchase_type&depart_code=$depart_code&project_status=$project_status&bidder_way=$bidder_way";
  $config['base_url'] = site_url('project/project_search').$suffix;
  $config['total_rows'] = $this->db->count_all($this->db->dbprefix('project'));
  $config['per_page'] = 10;
  $config['page_query_string'] = TRUE;
  //偏移量
  $config['query_string_segment'] = 'page';
  $config['uri_segment'] = 3;
  $this->pagination->initialize($config);
  $user = $this->user_mdl->get_user_by_salary_no($this->session->userdata('salary_no'));
  $this->db->from('ustc_project');
  $this->db->join('ustc_admins','ustc_admins.salary_no=ustc_project.salary_no');
  if($user->role!=1){
    $depart_code = explode(',',$user->grant_depart_code);
    $this->db->where_in('grant_depart_code',$depart_code);
    $this->db->or_where('ustc_project.salary_no =',$this->session->userdata('salary_no'));
  }
  if($name != ''){
    $this->db->like('name',$name);
  }
  if($username != ''){
    $this->db->like('username',$get_data['username']);
  }
  if($budget != ''){
    $this->db->like('budget',$get_data['budget']);
  }
  if($type != ''){
    $this->db->where('type',$get_data['type']);
  }
  if($depart_code != ''){
    $this->db->where('depart_code',$get_data['depart_code']);
  }
  if($purchase_type != ''){
    $this->db->where('purchase_type',$get_data['purchase_type']);
  }
  if($project_status != ''){
    $this->db->where('project_status',$get_data['project_status']);
  }
  if($bidder_way != ''){
    $this->db->where('bidder_way',$get_data['bidder_way']);
  }
  //时间
  if($posttime_start != ''){
    $this->db->where('posttime > ',strtotime($get_data['posttime_start']));
  }
  if($posttime_end != ''){
    $this->db->where('posttime < ',strtotime($get_data['posttime_end']));
  }
  if(isset($get_data['page'])){
    $page_from = $get_data['page'];
  }else{
    $page_from = 0;
  }
  $this->db->order_by('posttime','desc');
  $projects = $this->db->limit($config['per_page'],$page_from)->get()->result_array();  
  //处理
  for($i=0;$i<count($projects);$i++){
    $projects[$i]['type'] = $this->manage_info_mdl->get_value_by_id($projects[$i]['type'])->value;
    $projects[$i]['purchase_type'] = $this->manage_info_mdl->get_value_by_id($projects[$i]['purchase_type'])->value;
    $projects[$i]['depart'] = $this->depart_mdl->get_depart_by_code($projects[$i]['depart_code'])->name;
  }
  $data['projects'] = $projects;
  //获取当前用户的角色
  $data['user_role'] = $this->user_mdl->get_user_by_salary_no($this->session->userdata('salary_no'))->role;  
  $this->_template('project_search',$data);
}

希望本文所述对大家基于codeigniter的php程序设计有所帮助。

相关文章

  • 分享一则PHP定义函数代码

    分享一则PHP定义函数代码

    这篇文章主要介绍了分享一则PHP定义函数代码,主要是让大家熟悉下php的语法格式以及php中插入HTML代码的方式,希望能够给到大家一些帮助。
    2015-02-02
  • php写入mysql中文乱码的实例解决方法

    php写入mysql中文乱码的实例解决方法

    在本文里小编给大家整理的是关于php写入mysql中文乱码的解决方法和知识点,有需要的朋友们参考下。
    2019-09-09
  • discuz图片顺序混乱解决方案

    discuz图片顺序混乱解决方案

    本文给大家分享的是在discuz论坛中上传多张图片,直接发表帖子的时候图片顺序有时候会乱掉的解决办法,十分的简单,有需要的小伙伴可以参考下。
    2015-07-07
  • php防攻击代码升级版

    php防攻击代码升级版

    我上一篇文章《最新开发的网站防IP攻击代码,超级有用》写了一个完整的防止网络恶意IP攻击的方案,使用了一个月,效果良好。
    2010-12-12
  • 修改PHP脚本使WordPress拦截垃圾评论的方法示例

    修改PHP脚本使WordPress拦截垃圾评论的方法示例

    这篇文章主要介绍了修改PHP脚本使WordPress拦截垃圾评论的方法示例,主要是通过修改主题的functions.php来实现相关功能,需要的朋友可以参考下
    2015-12-12
  • 在windows服务器开启php的gd库phpinfo中未发现

    在windows服务器开启php的gd库phpinfo中未发现

    在windows服务器开启php的gd库时,使用cgi之后phpinfo()得到的结果中 Configure Command 中并没有出现gd,很是疑惑,于是搜集了一些,希望对你们有帮助,感兴趣的朋友可以了解下
    2013-01-01
  • PHP使用XMLWriter读写xml文件操作详解

    PHP使用XMLWriter读写xml文件操作详解

    这篇文章主要介绍了PHP使用XMLWriter读写xml文件操作,结合实例形式分析了php基于XMLWriter针对xml文件进行读写操作相关实现技巧,并附带相关源码供读者下载参考,需要的朋友可以参考下
    2018-07-07
  • php获取指定范围内最接近数的方法

    php获取指定范围内最接近数的方法

    这篇文章主要介绍了php获取指定范围内最接近数的方法,可实现根据给定区间长度划分各个区间,并在其中寻找与给定数最接近的数,需要的朋友可以参考下
    2015-06-06
  • php取得字符串首字母的方法

    php取得字符串首字母的方法

    这篇文章主要介绍了php取得字符串首字母的方法,支持中文字符串的操作,涉及php操作字符串的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-03-03
  • PHP使用file_get_contents发送http请求功能简单示例

    PHP使用file_get_contents发送http请求功能简单示例

    这篇文章主要介绍了PHP使用file_get_contents发送http请求功能,结合实例形式分析了file_get_contents结合stream_context_create实现的发送post请求数据相关原理与操作技巧,需要的朋友可以参考下
    2018-04-04

最新评论