codeigniter實(shí)現(xiàn)get分頁(yè)的方法
更新時(shí)間:2015年07月10日 09:20:31 作者:mckee
這篇文章主要介紹了codeigniter實(shí)現(xiàn)get分頁(yè)的方法,涉及使用codeigniter框架查詢數(shù)據(jù)量及針對(duì)結(jié)果集進(jìn)行g(shù)et方法分頁(yè)的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下
本文實(shí)例講述了codeigniter實(shí)現(xiàn)get分頁(yè)的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
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分頁(yè)配置
$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']);
}
//時(shí)間
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;
//獲取當(dāng)前用戶的角色
$data['user_role'] = $this->user_mdl->get_user_by_salary_no($this->session->userdata('salary_no'))->role;
$this->_template('project_search',$data);
}
希望本文所述對(duì)大家基于codeigniter的php程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- CI框架常用經(jīng)典操作類總結(jié)(路由,偽靜態(tài),分頁(yè),session,驗(yàn)證碼等)
- CI框架(ajax分頁(yè),全選,反選,不選,批量刪除)完整代碼詳解
- Codeigniter(CI)框架分頁(yè)函數(shù)及相關(guān)知識(shí)
- PHP CodeIgniter分頁(yè)實(shí)例及多條件查詢解決方案(推薦)
- CodeIgniter分頁(yè)類pagination使用方法示例
- Codeigniter框架實(shí)現(xiàn)獲取分頁(yè)數(shù)據(jù)和總條數(shù)的方法
- codeigniter中測(cè)試通過(guò)的分頁(yè)類示例
- CI框架簡(jiǎn)單分頁(yè)類用法示例
相關(guān)文章
php實(shí)現(xiàn)通過(guò)cookie換膚的方法
這篇文章主要介紹了php實(shí)現(xiàn)通過(guò)cookie換膚的方法,通過(guò)cookie存儲(chǔ)用戶選擇信息實(shí)現(xiàn)換膚效果,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07
php簡(jiǎn)單瀏覽目錄內(nèi)容的實(shí)現(xiàn)代碼
本篇文章是對(duì)php簡(jiǎn)單瀏覽目錄內(nèi)容的實(shí)現(xiàn)代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
php字符串函數(shù)學(xué)習(xí)之strstr()
這篇文章主要介紹了php字符串函數(shù)學(xué)習(xí)之strstr(),本文講解了它的定義和用法、參數(shù)描述、提示和注釋以及多個(gè)使用示例,需要的朋友可以參考下2015-03-03
Laravel快速入門之composer介紹及安裝詳細(xì)圖文步驟
這篇文章主要介紹了Laravel快速入門之composer 介紹以及安裝詳細(xì)圖文步驟,圖文步驟講解的很清楚,有對(duì)這方面不懂的同學(xué)可以研究下2021-01-01
PHP測(cè)試框架PHPUnit組織測(cè)試操作示例
這篇文章主要介紹了PHP測(cè)試框架PHPUnit組織測(cè)試,結(jié)合實(shí)例形式分析了PHPUnit組織測(cè)試具體步驟、相關(guān)命令與操作技巧,需要的朋友可以參考下2018-05-05

