PHP implementation CodeIgniter pagination and multi-conditional query solution

Source: Internet
Author: User
Tags codeigniter
This article mainly introduces PHP CodeIgniter page instance and multi-conditional query ideas, very good, with reference value, the need for friends can refer to the next

Recently in the use of the CI framework, the use of CI-page class, used to be the front end of the whole page, this time simply use the framework of their own, this forgetful head, or record it.

Because there are conditionally filtered forms in the page, the effect that you want to accomplish is that after you enter a condition, the page jumps to maintain the criteria you entered. Think about it, your own idea is the following code.

Controller code

Class Monitors extends Ci_controller {public Function warning () {$config = array (); $config [' per_page '] = 15; The number of data displayed per page $current _page = intval ($this->input->get ("Per_page"); Gets the current paging page number $status = $this->input->get ("Filter-status", TRUE); $level = $this->input->get (' Filter-level ', TRUE);    $timestamp = $this->input->get (' Filter-timestamp ', TRUE);   $all = $this->monitors_m->getalldata ($current _page, $config [' Per_page '], $status, $timestamp, $level); This returns the total number of bars and the specific data, according to their own circumstances slightly modified can be $data [' allevent '] = $all [' content '];  $config [' total_rows '] = $all [' Count '];//total number of bars $config [' num_links '] = 3;//number of connections $config [' use_page_numbers '] = TRUE; $config [' page_query_strings '] = true;//key configuration $config [' base_url '] = Base_url (). ' Index.php/monitors/warning? ' &filter-status= '. $status. ' &filter-level= '. $level. ' &filter-timestamp= '. $timestamp;//Key Configuration $this->load->library (' pagination ');//Load CI pagination class $this Pagination->initialize ($config); $data [' page '] =$this->pagination->create_links ();//Key Code $this->load->view ("Monitors_v", $data);} 

Key configuration Parameters

$config [' page_query_string ']

If set to True, then the URL is "index.php/monitors/warning?" Per_page=20 "Such a

Note "Per_page" is a query string passed by default, but can also be configured with $config [' query_string_segment '] = ' your string '

In my scenario, set to true, and of course true is the default value, either;

$config [' Base_url ']

At first, it is only possible to set conditional filtering on a page, but there is no problem condition for the refresh after the jump.

$config [' base_url '] = Base_url (). ' index.php/monitors/warning;

You can use the following method, Roar and Roar

$status = $this->input->get ("Filter-status", true); $level = $this->input->get (' Filter-level ', true); $ timestamp= $this->input->get (' Filter-timestamp ', TRUE); $config [' base_url '] = Base_url (). ' Index.php/monitors/warning? ' &filter-status= '. $status. ' &filter-level= '. $level. ' &filter-timestamp= '. $timestamp;//Key configuration

View page code

In a word, add this to the place where you need to place the pagination element, where the $page variable is stored inside the controller.$this->pagination->create_links();

<?php Echo $page?>

Set the paging style

This is the bootstrap style.

$config [' first_link ']   = "<<";//Home $config[' prev_link ']   = "<";//Previous page $config[' Next_link ']   = " > ";//Next page $config[' last_link"   = ">>";//Last $config[' full_tag_open '] = ' <ul class= ' pagination Pagination-split ">"; $config [' full_tag_close '] = ' </ul> '; $config [' first_tag_open '] = ' <li> ';//the start tag of the first link. $config [' first_tag_close '] = ' </li> ';//the end tag of the first link. $config [' next_tag_open '] = ' <li> ';//the start tag of the next page link. $config [' next_tag_close '] = ' </li> ';//the end tag of the next page link. $config [' prev_tag_open '] = ' <li> ';//the start tag of the previous page link. $config [' prev_tag_close '] = ' </li> ';//the end tag of the previous page link. $config [' cur_tag_open '] = ' <li class= ' active ><a> '; $config [' cur_tag_close '] = ' </a></li> '; /end tag of the current page link. $config [' num_tag_open '] = ' <li> ';//the start tag of the digital link. $config [' num_tag_close '] = ' </li> ';//the end tag of the digital link.

Related Article

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.