CodeIgniter Forums
Problem with cache data - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: Problem with cache data (/showthread.php?tid=66059)

Problem with cache data - StratoKyke - 08-30-2016

I hope you can understand my problem.

I currently have a table with Pagination Class and presents a auto increment number

The obvious problem is that when I use the search function

It was presented everything correctly but the auto increment number remains at 1.

How can I make sure to use a caching system to save the entire table including the increment number and then use the Pagination Class of the data?

In this way the number of position is correctly when I search a data.

RE: Problem with cache data - StratoKyke - 08-30-2016

I was thinking of doing something with queries like this

@rownum := @rownum + 1 as row_number

How to implement with active record?

RE: Problem with cache data - StratoKyke - 08-31-2016

Someone can help me?

RE: Problem with cache data - PaulD - 08-31-2016

Your question is unclear. When you do a search you get a new set of results. Those results may or may not need pagination. Why would you save the entire table? It could be huge. Do you mean cache the search results?

RE: Problem with cache data - StratoKyke - 08-31-2016

In this moment I use the cache system for queries ,but in Table I go to print, there is a position, which is nothing but a self incrementing number.

Like this for example:
1. ccc
2. ddd
3. bbb

When I use search to find ddd the position is obviously 1.

I would like to understand how to solve the problem. Perhaps by including the position in the cache?

RE: Problem with cache data - PaulD - 08-31-2016

Oh, I see. So you want to retain the incremented row number. It sounds like you are numbering the rows automatically with a counter and incrementing the counter for each row.

Instead you could use the ID for the row you are displaying, that will never change, but then your table will not be numbered from 1, and would look strange. If it is just a counter though it is right that it always starts from one, or after a search you will get 3 gggg, 12 thfhs, 24 fsdfsdf etc, which will also look strange.

You could just output #1 in that column indicating it is just a row number, or have at the top of the table 'Displaying 1-24 or 24 results, which would make the idea that the column is just counting more obvious. You cannot have it both ways, either it is a reference number to the row, so will not be 1,2,3,4, or it is not a reference in which case it will always start at 1.

The only other way is to download the entire table on first go, but when a search is done, do it via js that then just sets the unwanted rows to display:none, which would hide the unwanted results. Your javascript would work it's way through the table row by row, taking the search field content, doing a search match test, hiding the row if no match found. You could then add a button to clear the search filter, which would be another JS function to remove all the diplay:none stylings or classes. That might work nicely as two searches in a row would mean the second search is a search on the current displayed search results, so you could slowly refine your search if you have a lot of data.

Hope that helps in some way,

Best wishes,


RE: Problem with cache data - StratoKyke - 08-31-2016

But it would be possible to do with cache system?

RE: Problem with cache data - PaulD - 08-31-2016

You mean do it in the controller? Yes I suppose but it seems a strange thing to do. Again it is NOT a reference number, if it was you would not be having this problem.

In the controller you get all the results, cache them if you want to. Loop through them and add to each row a field for count #1,2,3 and, if there is a search being done: another field for if the row matches the search criteria or not. Output to page.

On the page, if there is a search, only show rows that have been marked as matching the search. This will keep the integrity of the original count but only display the search results.

This all seems mad though.

Did you mean that when you use pagination and go to page 2, the row number still starts at 1. That is easily solved by just setting your counter to the page number minus 1 times the number of results per page + 1

PHP Code:
$counter = (($page_number 1) * ($results_per_page) ) + 1

So page one starts at counter=1, page 2 starts as 21 (assuming 20 results per page), page 3 at 41 etc,

Is that wahy you meant?