Welcome Guest, Not a member yet? Register   Sign In
class pagination produce wrong page links


i am using CI Version 2.0.0

i try to create pagination in my controller

$config['uri_segment'] = 4;
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = '6';
$config['per_page'] = '5';



its produce paginatoin link is

1 2 >

its produce wrong page link 'http://example.com/index.php/test/page/5'

Sorry, what link was you expecting?

I believe that pagination has always shown the record instead of the page number.

So, in your case. If you had 5 pages it would appear as following.

1 -> 0
2 -> 5
3 -> 10
4 -> 15
5 -> 20

This number would then be used by your database to limit the number of database results.


pls check this code correctly. i explain

total rows is 6 to assign config

$config['total_rows'] = '6';

per_page is 5 to assign config.its meaning num of data show per page(5 datas)

$config['total_rows'] = '5';


$numPages = ceil($config['total_rows']/$config['total_rows']);

answer is 2

in case current page is 1 also next page is 2,but CI produce 5

1 2 >

http://example.com/index.php/test/page/5 url segment value is 5 its wrong.

I FIND SOLUTION .i have change some lines in function create_links

This is what I am saying, it isn't incorrect. CI is producing the record number, not the page number. Look at the pagination on the forum (which I assume is built with CI), has exactly the same pagination structure.

If you change per_page to 10 then page 2 should show '/10', if you change it to 100 it should show '/100'

@jobin dcruz:
As JasonS stated, you are looking wrong at the code.

total_rows is how many results are there to paginate.
Let's say:

total_rows = 100;
per_page = 10;

Then, you will have total of 10 links (10 x 10 = 100);
If you set:
per_page = 5;
you will end up with 20 pagination links (5 x 20 = 100).

URL: http://example.com/index.php/test/page/5
The number 5 means in pagination class where to start from in total_rows on that page.
So, when you click it, pagination class will do:
show $per_page from $total_rows and start at 5
in other words:
show 5 results, from total of 100 results but start showing from result 5 (to 10).

So, link is correct. You are simply looking wrong at it :-)


Theme © iAndrew 2016 - Forum software by © MyBB