Finding the number of results from a SELECT query


show more Finding the number of results from a SELECT query provides you with in-depth training on Developer. Taught by David Powers as part of the Accessing Databases with Object-Oriented PHP show less
please wait ...

Finding the number of results from a SELECT query

When you run a select query, it's useful to know how many results have been returned. If there are no results, you need to display a suitable message, or to hide parts of the page, or both. Some databases like MySQL, report the number of rows in a result set. But most don't. We look first at how to get the number if it's reported. Then we'll look at a technique that works in all databases. This is pdo_rowcount.php which you can find in the chapter two, ch02 > 02_05 folder of the exercise files.

The page has a select query. It executes it, and then the results are displayed in a table. The PDO row count method, returns the number of results in a results set, if it's reported by the database. So let's go back up to the top. There is our result set there. So if we create a variable called num_rows, and then use the result object, and call the row count method, that should give us the number of results if it's reported.

And we can then display that value, just before the table h...

Finding the number of results from a SELECT query
Video duration: 7m 14s 3h 47m Intermediate

Viewers:

Finding the number of results from a SELECT query provides you with in-depth training on Developer. Taught by David Powers as part of the Accessing Databases with Object-Oriented PHP

Subject:
Developer
Software:
PHP
Author:
please wait ...