Main Content

How to show a large result set page by page in PHP

Archive - Originally posted on "The Horse's Mouth" - 2010-02-11 07:22:35 - Graham Ellis

One of the major requirements on dynamic web pages is for them to present selected results from a data set.

If the results will nicely fit on one page, that's good - but if there are too many for a single page they should be offered page by page, with links to move forward and back, and to the beginning and end. Where there are a very large number of results, even a list of page numbers to link to can be excessive and there should be a mechanism for adding "..." over sections of the page list.

And if there are no results at all, it's useful to the user of your page to suggest to him/her "did you mean" and offer the closest alternative(s).

Taking a simple but long data file as my source, I wrote a demonstration of such a system on Tuesday - the well commented source code is [here] and you can try it out [here]. Try it out with "on", "ington", "o" and "Hoxham" to see the various results. If you want to learn how to write things like this for yourself, our PHP Technology Workshop covers this sort of thing very fully.