I've revisited CodeIgniter's pagination class.
I've viewed many tutorials online as the documentation lacks details.
So I copy pasted the tutorial and changed some relevant details to suit a random table I have.
Controller:
public function sample_pagination($offset = 0){
$num_rows=$this->db->count_all("genre");
$config['base_url'] = base_url().'pages/sample_pagination/';
$config['total_rows'] = $num_rows;
$config['per_page'] = 5;
$config['num_links'] = $num_rows;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$data['records']=$this->db->get('genre', $config['per_page'],$offset);// take record of the table
$header = array('genre_Id','name'); // create table header
$this->table->set_heading($header);// apply a heading with a header that was created
$this->load->view('pages/sample',$data); // load content view with data taken from the users table
}
The view:
<body>
<div id="container">
<h1>Welcome to CodeIgniter Pagination System!</h1>
<div id="body">
<?php echo $this->table->generate($records); ?>
<?php echo $this->pagination->create_links(); ?>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
</body>
It's working fine, the only problem i have is that, the database table genre i have has 14 entries and the results on the view vary depending on the per_page settings.
say for example above, i set the per_page to 5. It will show 5 rows per page of the pagination with 3 pagination links < 1 2 3 >
the problem is that the details only showed up to the 8th row of the table which had 14 rows and it repeated.
First page is
1 2 3 4 5
second page is
3 4 5 6 7
third page is
4 5 6 7 8
I'm referring to the genre_id at the above. My table genre has genre_id as PK and genre_name as a col. so it only has 2 columns.
Anyway, if i set the Per_page to 1, it shows all the table rows correctly from genre_id 1 to 14.
I'm confused how this is happening? I learn easily via doing it myself so i tried doing it by copying tutorials online so i can see how it works but im getting confused by this.
sample_pagination
is the controller right? and you are passing the page number as an offset? that's not how you do it. – Spoody