Page 1 of 1

Pagination question

Posted: Sat Apr 17, 2010 6:00 am
by siko
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?

Re: Pagination question

Posted: Sat Apr 17, 2010 6:55 am
by JAY6390
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

Re: Pagination question

Posted: Sat Apr 17, 2010 11:50 am
by social_experiment
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.
You should use the following instead :

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