CodeIgniter pagination usage example, codeigniter example

Source: Internet
Author: User
Tags codeigniter

CodeIgniter pagination usage example, 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(),    );}

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.