HomePHP Previous or Next? Paginating Records with PHP - Part 3
Previous or Next? Paginating Records with PHP - Part 3
In part three of our series about paginating records with PHP, we will learn how to make our application work with a relational database system such as MySQL. We will develop a tight, compact PHP class, capable of performing the most common paging tasks efficiently.
Welcome to part three of the series "Previous or Next? Paginating Records with PHP." I hope that you've had a good time reading the previous articles, where we strongly focused our attention on implementing several approaches to paginate data in websites, using PHP's excellent capabilities. So far, we've developed a couple of methods for displaying chunks of data, appending the proper paging links, and providing an easy way to navigate across pages.
In the first case, we explored a procedural approach for dealing with the topic, defining a function to paginate data coming from a simple text file. This approach is suitable for small applications. Analogously, in the second case, we utilized a plain text file as a data source, but this time we built up a paging PHP class to generate the visual data output and the paging links. However, our newly developed "Pager" class presents some issues that need to be properly addressed.
Since the Web is now driven almost entirely by databases, we should be able to work with a relational database system such as MySQL to paginate result sets, and have the possibility of applying an effective visual format to retrieved records. To meet real world needs, it's highly imperative to develop a tight, compact PHP class, capable of performing the most common paging tasks efficiently, with minor hassles at most. So, let's jump straight into the class code and create this new toy for our developer's toolbox.