Pagination from search results |
[eluser]garycocs[/eluser]
Hi Lads, I'm sure this was asked before but I can't seem to find anything about it. Soooo basically I have my search queries being returned to a controller, search1, search2 and search3 which I pass to my model and my model returns the list of results. Obviously I want to paginate these results. My first question is then, how do I calculate the overall results, do I first have to compute how many results from the overall query and then run the query again to output the number I have limited each page to? That then means I'm running basically the same db query twice?? Next how do I use pagination on post variables? i.e. variables returned from a large form? How do I attach these variables to the url so the next page can pull these variables? Thanks for your time, //Gary
[eluser]pickupman[/eluser]
Yes, you could run the query the query twice. You may want to use a COUNT(field) query with a where statement. The count query would probably be faster the running the full query. Example: Code: $this->db->select('COUNT(item) as rows'); Or you could use DB query caching ($this->db->cache_on() & $this->db->cache_off()), that way the database result would be saved to disk. Use the benchmarking class to see what works the fastest for your dataset. If you go the caching route, you have to make sure you delete the cache files if you have changed the database. Take a look at Phil Sturgeon's cache library for cache files that will auto expire. On your second question on storing or passing the search parameters, you'll find it easiest to store that in a user's session. Code: $this->session->set_userdata('keyword',$keyword); //set value
[eluser]garycocs[/eluser]
Thanks for the reply I'll look into the user session so and I reckon I'l avoid cacheing for the time being ![]() As for the number of search parameters, mostly 2 or 3 but sometimes up to 10!! |
Welcome Guest, Not a member yet? Register Sign In |