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 ... |
Get PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.