Say if I have a search page on my site that allows many search options and criterias, and results are generally a couple of hundreds records for each search, pulled from a database of around 20,000 records, and I'll need to paginate the results.
I'm thinking of the following algorithm, which is what most PHP pagination scripts I've found out there are doing:
Search 20,000 records based on specified search criteria and count the number of results.
Total count of results / Number of records I want to display per page, and display the pagination links accordingly.
Display results for the current page.
That pretty much works, but the thing is.. seems like I'll have to peform the search again everytime I want to look at another page of the results, in which case I'll have to somehow pass my search criterias for this search through GET or POST in order for the search to be done again? Is it supposed to be this way?
Pagination question
Moderator: General Moderators
Re: Pagination question
Hi Siko
Yes that is pretty much the way it will work. You could of course just save the criteria in a session variable and just have a checksum passed via GET or POST to verify it's the same search query
Also, if you'd like an easy way of creating pagination results with PHP take a look at my simple php pagination class
Regards
Jay
Yes that is pretty much the way it will work. You could of course just save the criteria in a session variable and just have a checksum passed via GET or POST to verify it's the same search query
Also, if you'd like an easy way of creating pagination results with PHP take a look at my simple php pagination class
Regards
Jay
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Pagination question
You should use the following instead :siko wrote:Search 20,000 records based on specified search criteria and count the number of results.
Total count of results / Number of records I want to display per page, and display the pagination links accordingly.
Display results for the current page.
1.Count the records using COUNT() [assuming you are using sql] with your search query
2.Total count of results / Number of records per page
3.Search query (get results)
4.Display results
5.Create pagination links
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering