The example of this article describes how to use the CodeIgniter page class pagination. Share to everyone for your reference, as follows:
Controller controllers (application/controller/page.php files):
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 number of page pages currently paged//page restore if (0 = = $current _page) {$current _page = 1; } $offset = ($current _page-1) * $config [' per_page ']; Set offset qualification data query start position (starting with $offset bar) $result = $this->home_model->index ($offset, $config [' Per_page '], er = ' id des C '); $config [' base_url '] = $this->config->item (' Base_url '). ' Admin/home/index? '; $config [' first_link '] = $this->first_link;//home $config [' prev_link '] = $this->prev_link;//prev $config [' Next_link '] = $this->next_link;//next $config [' last_link '] = $this->last_link;//last $config [' Total_rows ' ] = $result [' Total '];//number $config [' num_links '] = 3;//number of connections $config [' use_page_numbers '] = TRUE; $config [' page_query_string '] = TRUE; $thisLoad->library (' pagination ');//Load CI pagination class $this->pagination->initialize ($config); $result = Array (' list ' = = $result [' list '], ' total ' and ' = ' $result [' total '], ' current_page ' = $current _page, ' per_page ' = $config [' per_page '], ' page ' and $this->pagination->create_links (), ); $this->load->view (' Admin/home ', $result);}
Model models (application/model/home_model.php file):
Public Function Index ($offset, $num, er = ' id desc ') { $query = $this->db->query ("Select Name_cn,mall_type, Create_time from smzdm_mall WHERE is_deleted = 0 ORDER by {er} 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 this site topic: "CodeIgniter Introductory Tutorial", "CI (codeigniter) Framework Advanced Tutorial", "PHP date and Time usage summary", "PHP object-oriented Programming introduction Tutorial", " PHP String Usage Summary, "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"
It is hoped that this article is helpful to the PHP program design based on CodeIgniter framework.