CodeIgniter pagination class Pagination Use Method Example _php instance

Source: Internet
Author: User
Tags codeigniter

This article gives an example of how to use the CodeIgniter paging class pagination. Share to everyone for your reference, specific as follows:

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

The Public Function index () {$this->load->model (' Home_model ', ', TRUE ');
    $config = Array (); $config [' per_page '] = $this->per_page; The number of data displayed per page $current _page = intval ($this->input->get_post (' Per_page ', true);
    Gets the current paging page number//page restore if (0 = $current _page) {$current _page = 1; } $offset = ($current _page-1) * $config [' per_page ']; Sets the offset to qualify the starting position of the data query (starting with $offset bar) $result = $this->home_model->index ($offset, $config [' Per_page '], $order = ' id de
    SC '); $config [' base_url '] = $this->config->item (' Base_url '). '
    Admin/home/index? '; $config [' first_link '] = $this->first_link;//home page $config [' prev_link '] = $this->prev_link;//prev $config [' next_link '] = $this->next_link;//the next page $config [' last_link '] = $this->last_link;//last $config [' Total_r
    oWS '] = $result [' Total '];//number $config [' num_links '] = 3;//number of connections $config [' use_page_numbers '] = TRUE; $config [' page_query_string '] = TRUE;
    $this->load->library (' pagination ');//Loading CI pagination class $this->pagination->initialize ($config); $result = Array (' list ' => $result [' list '], ' total ' => $result [' Total '], ' current_page ' =&G T $current _page, ' per_page ' => $config [' per_page '], ' page ' => $this->pagination->create_links ()
    ,
    );
$this->load->view (' Admin/home ', $result);

 }

Model models (application/model/home_model.php files):

The 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 (),
    );
}

More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP date and Time usage summary", "PHP object-oriented Program Design Introductory Course", " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips

I hope this article will help you with the PHP program design based on CodeIgniter framework.

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.