Real life dynamic, data-driven web applications are very different from each other, as their complexity is dictated by the purposes that they serve. However, almost all of them have some common characteristics. One of these characteristics is the ability to paginate long result lists for ease of use and faster page loading times.
Correct pagination requires the calculation of the number of total rows returned from the database, the page size (which is a configurable option), and the number of current page. Based on this data, it is easy to calculate the starting offset into the result set to display only a subset of rows.
In this chapter, we will examine:
How to retrieve the number of rows in the result sets returned by PDO
How to fetch results starting at a specified row number
As we have already discussed in Chapter 2, the PDOStatement::rowCount()
method does not return the correct number of rows in a query. (It returns...