HomePHP Previous or Next? Paginating Records with PHP, part 1
Previous or Next? Paginating Records with PHP, part 1
Putting all of your content for a particular file on one page can be very user unfriendly to website visitors. Nobody likes to be confronted by a tiny vertical scroll bar! In this article, the first in a series, you will learn a simple way to paginate records from a text file using PHP.
We see it every day, when surfing the Web looking for new content to expand our background as Web developers. More and more websites offer vast amounts of fresh information to satisfy users and keep them coming back for more. Most of the time, data is stored in databases and displayed according to user requests, in a fairly decent way, sticking more or less to the principles of readability. So, what's wrong about it?
If we take a look at some popular professional websites, we immediately notice that they offer some kind of paginating mechanism to display database records. From simple "previous" and "next" navigational links, to more complex numerated links, the range is quite wide. Let's take the case of Google, for showing an excellent example of a sophisticated and efficient paginating system. Fine, let's admit it. Here, we're talking about the big boys who most of the time (but certainly not always) do know what approach to take when dealing with record paging.
But, what about the others? Don't tell me that you never had to suffer that annoying experience of finding a website that happily loads its content, while you're watching with a feeling of growing panic as the vertical scroll bar control gets tinier and tinier! Oh, is that a severe punishment, or what?
But let's stop being ironic and face the problem that we have here. Showing elegant, paginated information gives our sites a very polished look, and certainly is a great way to enhance readability for visitors. Thus, the subject is relevant enough to be seriously considered. That's where this article comes in. We're going to present different approaches for implementing an efficient paginating mechanism using PHP, which hopefully will be useful to employ on any existing or future Web projects. So, let's jump to the next section to find out more.