Model Layer
Publicfunction Get_content ($start, $num) {
$sql ="SELECT * From content limit $start, $num";//$start = The index corresponding to the first data on each page; the number of bars that are fixed for each page of the $num = =
$query = $ This->db->query ($sql);
return$query->result ();
}
Controllers Layer
PublicFunction index ()
{
$num =2;
$page = $ This->uri->segment (3);
if(Empty ($page)) {
$start =0;
}Else{
$start = $page;
}
$data ['Results'] = $ This->voice_model->get_content ($start, $num);//according to $start (the starting value of each page index) and $num (the number of each page to display) go to the database to fetch
$total = $ This->db->count_all ('content');//calculate the total number of data in the table news in the database
$config ['Base_url'] = Base_url ().'Index.php/content_control/index';//Configure URLs
$config ['total_rows'] = $total;//total number of bars
$config ['Per_page'] = $num;//number shown on first page
$ This->pagination->initialize ($config);//Call the Initialize function with the CI itself
$ This->load->view ('content.html', $data);//passes the contents of the array $data to the view page knowledge.php
}
Views Layer
<?php echo $ This->pagination->create_links ();? >
CI Framework Pagination Class Code