0
votes

Last days I am playing with CI's pagination. I already set up config and the thing works perfectly. In the function of controller I have created some IF statements which are checking url.

IF url is localhost/CI/index.php/controller/function/news
THEN return first page of results from database -> first page
BUT IF url is localhost/CI/index.php/controller/function/news/10
THEN return second page of results from database -> second page

But there's problem because CI's pagination works with navigation only if there is number of results after the controller's function -> localhost/CI/index.php/controller/function/10 .

Is there any workaround to do navigation with url like this localhost/CI/index.php/controller/function/news/10 ? (I have news, categories and other functions where I would like to show some basic informations about it.)

1

1 Answers

0
votes

First of all you don't need to have if statements to check if it's the first page or second ,etc... Codeigniter will display the appropriate data. But what you can do is check if the page number is there.

The way pagination works is by using the offset, and limit functionality of a database.

So page 1 would be: limit 5(max per page), offset: 0 (starting at 0) Page 2: limit 5(max per page), offset: 6

Typically codeigniter would check if the url segment(3 by default) is valid, if not then it would go and get page 1.

It might be the code itself that is incorrect, you might want to post it.