counting records in db
| From: | afan at afan dot net | Date: | Thu, 26 Oct 2006 17:38:09 +0000 |
| Subject: | counting records in db | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-243686@lists.php.net to get a copy of this message | ||
hi!
what would be better solution to count records in table (e.g., how many
customers have last name 'Smith'):
$query = mysql_query("
SELECT COUNT(*) as NoOfRecords
FROM customers
WHERE last_name = 'Smith'");
$result = mysql_fetch_array($query);
$NoOfRecords = $result['NoOfRecords'];
OR
$query = mysql_query("
SELECT cust_id
FROM customers
WHERE last_name = 'Smith'");
$NoOfRecords = mysql_num_rows($query);
OR something else?
Thanks.
-afan