CodeIgniter pagination usage example, codeigniter example _ PHP Tutorial

Source: Internet
Author: User
CodeIgniter pagination usage example, codeigniter example. CodeIgniter pagination usage example. codeigniter example this article describes how to use CodeIgniter pagination. For your reference, refer to the following code: CodeIgniter pagination usage example and codeigniter example.

This example describes how to use the pagination paging class of CodeIgniter. We will share this with you for your reference. The details are as follows:

Controller (application/controller/page. php file ):

Public function index () {$ this-> load-> model ('Home _ model', '', TRUE); $ config = array (); $ config ['per _ page'] = $ this-> per_page; // The number of data displayed on each page $ current_page = intval ($ this-> input-> get_post ('per _ page', true )); // Obtain the current page number. // restore the page if (0 = $ current_page) {$ current_page = 1;} $ offset = ($ current_page-1) * $ config ['per _ page']; // sets the offset to limit the start position of the data query (starting from $ offset) $ result = $ this-> home_model-> index ($ Fset, $ config ['per _ page'], $ order = 'Id desc '); $ config ['base _ url'] = $ this-> config-> item ('base _ url '). 'admin/home/index? '; $ Config ['first _ link'] = $ this-> first_link; // homepage $ config ['prev _ link'] = $ this-> prev_link; // Previous Page $ config ['next _ link'] = $ this-> next_link; // next Page $ config ['last _ link'] = $ this-> last_link; // at the end of the page $ config ['total _ rows '] = $ result ['total']; // The total number of items $ config ['Num _ links'] = 3; // page number of connections $ config ['use _ page_numbers '] = TRUE; $ config ['page _ query_string'] = TRUE; $ this-> load-> library ('pagination'); // load the ci pagination class $ this-> pagination-> initialize ($ config ); $ result = array ('list' => $ result ['list'], 'total' => $ result ['total'], 'current _ page' => $ current_page, 'per _ page' => $ config ['per _ page'], 'Page' => $ this-> pagination-> create_links (),); $ this-> load-> view ('admin/home', $ result );}

Model (application/model/home_model.php file ):

public function index($offset,$num,$order='id desc'){    $query = $this->db->query( "SELECT Name_cn,Mall_type,create_time FROM smzdm_mall WHERE Is_deleted = 0 order by {$order} limit {$offset},{$num}");    return array(        'total' => $this->db->count_all('smzdm_mall',array('Is_deleted'=>'0')),        'list' => $query->result(),    );}

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.