O'Reilly logo

PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Counting Returned Records

The next logical function to discuss is mysql_num_rows(). This function returns the number of rows retrieved by a SELECT query, taking the query result as a parameter.

$num = mysql_num_rows($result);

I’ll use this function in two different ways. First, I’ll modify view_users.php to list the total number of registered users. Second, I’ll modify register.php to test if an email address has already been taken before letting a user register with it.

To modify view_users.php

1.
Open view_users.php (refer to Script 7.4) in your text editor.
2.
Before the if ($result) conditional, add this line (Script 7.6)
$num = mysql_num_rows ($result);
Script 7.6. Now the view_users.php script will display the total number of registered ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required