CodeIgniter Forums
Pagination Bug - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Pagination Bug (/thread-9537.html)



Pagination Bug - El Forum - 06-29-2008

[eluser]Roosevelt![/eluser]
Hello,
I am not sure if it is a bug or an error in my code. For some reason when I generate
the pagination links, it generates the links as:

1 2 3 4

Where page 3 is linking to 4.

Code:
$this->load->library('pagination');
                            
$config['base_url'] = site_url("products/{$cat_id}/page/");
$config['total_rows'] = 10;
$config['per_page'] = $RowsPerPage; //using $this->db->count_all('products');
$config['uri_segment'] = 4;

echo $this->pagination->initialize($config);

So in a way, page three doesn't even exist.


Pagination Bug - El Forum - 06-29-2008

[eluser]Référencement Google[/eluser]
I think you inverted the total rows and per page, this should be:

Code:
$config['total_rows'] = $RowsPerPage; //using $this->db->count_all('products');
$config['per_page'] = 10;



Pagination Bug - El Forum - 07-01-2008

[eluser]Roosevelt![/eluser]
I typed the wrong code it is actually like this:

$config['base_url'] = site_url('products/browse/$category/page');
$config['total_rows'] = $TotalRows;
$config['per_page'] = $RowsPerPage;
$config['uri_segment'] = 5;

For testing purposes I set total_rows to 200, and per_page to 10, and removed the uri_segment config.

From what I figured out is that the page_num variable actually holds the offset value. But what I was doing is reassinging the offset again using the following math:

$offset = $pagenum * $rowsperpage.

So it was generating weird results :p.