php 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

$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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值