CodeIgniter method to implement get paging _php skills

Source: Internet
Author: User
Tags php programming codeigniter

The example in this article describes how CodeIgniter implements get paging. Share to everyone for your reference. The implementation method is as follows:

Public Function Project_search () {$this->load->library (' pagination ');
  $this->load->model (' depart_mdl ');
  Get the information that the search needs $data = $this->get_project_data ();
  $get _data = $this->input->get ();
  $data = Array_merge ($data, $get _data);
  Get paging configuration $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;
  Offset $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 ')); 
  }//Time 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 ();
 Processing 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; Gets the role of the current user $data [' user_role '] = $this->user_mdl->get_user_by_salary_no ($this->session->userdata ('  
  Salary_no ')->role;
$this->_template (' Project_search ', $data);

 }

I hope this article will help you with your PHP programming based on CodeIgniter.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.