note 11895 added to function.mysql-result.php
| From: | alec at brainpod dot com | Date: | Mon, 12 Mar 2001 18:28:42 +0000 |
| Subject: | note 11895 added to function.mysql-result.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-12302@lists.php.net to get a copy of this message | ||
"select count(*) from users" will return a table with one row and one field whith the
count of how many results the last select would have returned.
"select * from users" will return ALL the data from the rows that match this.
So using the second query followed by $mysql_num_rows to retrieve a count of rows is inefficient if
you don't need the actual data but just the count. Keep this in mind. Following is an example
of using the count function practically with MySQL:
select MONTHNAME(orderdate) as month, DAYOFMONTH(orderdate) as day, count(*) as volume from orders
group by month,day;
might produce something like this for a quick tally of sales:
+-------+------+--------+
| month | day | volume |
+-------+------+--------+
| March | 7 | 4 |
| March | 8 | 13 |
| March | 9 | 10 |
| March | 10 | 4 |
| March | 11 | 1 |
| March | 12 | 1 |
+-------+------+--------+
6 rows in set (0.01 sec)
Alec Effrat
alec@brainpod.com
http://www.php.net/manual/en/function.mysql-result.php