so many pagination question on stackoverflow, but i can’t see it with codeigniter, so here it goes.
we need to look at these picture

and here

and here

i have ten record on the table, and the link is not working, here is the controller/index
$query = $this->m_kategorimaterial->get();
$config['base_url'] = base_url().'index.php/c_kategorimaterial/index/';
$config['total_rows'] = $query->num_rows();
$config['per_page'] = 5;
$this->pagination->initialize($config);
$data['rows'] = $query->result();
$data['title'] = 'QB Kategori Material';
$this->load->view('menu',$data);
$this->load->view('v/vkategorimaterial');
and here is the model
$this->db->order_by('Kode_Kategori_Material_Jasa','DESC');
$query = $this->db->get('ms_kategori_material');
return $query;
why does the link is not working ? how do i resolve it ? Thank you stackoverflow
Where are you calling the offset in the data gathering query? You need to provide an offset to the query so it knows which records to get.
You’ll also have to change the total_rows to a second query that queries the entire table for total records since your new query only returns enough records for one page.
Model:
Controller:
Seems you could use a small explanation of what’s happening here. To do pagination CI (or any application) needs at minimum 3 variables.
limit – how many records per page should I show, and consequently how many records does my query return.
offset – Where does the query start asking for records, with CI this is where the uri segment comes in, it’s controlled partially by the limit so if you have 8 as a limit (per_page) each query increments the offset by 8. So page 1 queries the database for the first 8 records starting at the beginning, page two the first 8 records starting at record 9 and so on.
Total records – This is the total matching records for the query in the entire table(s). This is how the application determines how many pages there are in total and whether a second page is required at all. This query has no limit or offset because you want all the matching records and not a partial return.
The actual pagination of the data is carried out by the database query. CI just tells the database which records it needs.
Hope that helps clear things up.