I am doing a Pagination system in Codeigniter and something is not working properly.
I have a search that gives 5 results in total.
If I put 1 item per page it creates the pagination with the links as
example.com/suppliers/ Page 1
example.com/suppliers/1 Page 2
example.com/suppliers/2 Page 3
example.com/suppliers/3 Page 4
example.com/suppliers/4 Page 5
which is correct
But if I put 2 items per page tt appears as
example.com/suppliers/ Page 1
example.com/suppliers/2 Page 2
example.com/suppliers/4 Page 3
And if I put 3 items per page it appears as
example.com/suppliers/ Page 1
example.com/suppliers/3 Page 2
So it is jumping pages in an order of magnitude equivalent to the results per page.
This is the code used to generate the pagination:
//Create the pagination links
$config['base_url'] = base_url().'/suppliers';
$config['total_rows'] = $this->data['count_suppliers'];
$config['per_page'] = RESULTS_IN_SEARCH;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['prev_link'] = '<i class="fa fa-chevron-left"></i>';
$config['next_tag_open'] = '<li class="next">';
$config['next_tag_close'] = '</li>';
$config['next_link'] = '<i class="fa fa-chevron-right"></i>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close']='</li>';
$this->pagination->initialize($config);
$this->data['pagination']=$this->pagination->create_links();
In the image attached you can see the results.
SOLVED: Adding $config['use_page_numbers'] = TRUE; to the pagination configuration and when doing the query to the database substract 1 so the Page 1 searches for LIMIT 0, 3 instead of LIMIT 3,3
$config['use_page_numbers'] = TRUE;
– Naumov