I am making a Codeigniter 3 application, consisting of a table (with approximately 100 rows) that I have paginated, 10 rows per page.
In the home controller I have:
public function index() {
$this->load->model('Customer');
$this->load->library('pagination');
$config = [
'base_url' => base_url("index.php"),
'per_page' => 10,
'total_rows' => $this->Customer->get_num_rows(),
'uri_segment' => 3,
'first_tag_open' => '<li>',
'first_tag_close' => '</li>',
'last_tag_open' => '<li>',
'last_tag_close' => '</li>',
'full_tag_open' => '<ul class="pagination">',
'full_tag_close' => '</ul>',
'next_tag_open' => '<li>',
'next_tag_close' => '</li>',
'prev_tag_open' => '<li>',
'prev_tag_close' => '</li>',
'num_tag_open' => '<li>',
'num_tag_close' => '</li>',
'cur_tag_open' => '<li class="active"><a>',
'cur_tag_close' => '</a></li>',
];
$this->pagination->initialize($config);
$customers = $this->Customer->getCustomers($config['per_page'], $this->input->get('page'));
$this->load->view('home', ['records'=>$customers]);
}
In the Model file I have:
class Customer extends CI_Model {
public function __construct() {
$this->load->database();
}
public function getCustomers($limit, $offset) {
$this->db->limit($limit, $offset);
$query = $this->db->get('customers');
return $query->result();
}
}
The view:
<div class="pagination-container text-center">
<?php echo $this->pagination->create_links(); ?>
</div>
The first page looks good (I have recieved help from the comunuty with that. Thank you!):
The problem is that the second page shows records 3 to 13 instead of 11 to 20: