网络编程 
首页 > 网络编程 > 浏览文章

codeigniter实现get分页的方法

(编辑:jimmy 日期: 2024/11/5 浏览:3 次 )

本文实例讲述了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 = "";
  $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基于phpqrcode生成带LOGO图像的二维码实例
一句话新闻
一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap