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.