Skip to content
Advertisement

I’m having a problem with codeigniter pagination

When I create pagination without category it works, but with the category, it works with wrong data. With category pagination, it should show the data of a single category. But unfortunately, it shows mixed category data. These things work fine on the Index function….. In my index controller…

JavaScript

and my model for the index is …

JavaScript

It works perfectly. But when I try this on another function (category) It shows the data count right but shows wrong data in other pagination. Mainly this function is for categories the post data. Here is my controller…

JavaScript

And the model for this controller is …

JavaScript

Please help me solve this problem.

Advertisement

Answer

In your function get_posts_by_category()

JavaScript

You didn’t filter the posts of current category, so it returns mixed categories data. You can update like this:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement