Re: How make the time
| From: | Richard Lynch | Date: | Tue, 31 Jul 2001 09:21:53 +0000 |
| Subject: | Re: How make the time | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60371@lists.php.net to get a copy of this message | ||
>The client wants to get a report written out over each hour like this:
>
>11:00 2 Customers
>11:15 32 Customers
>11:30 12 Customers
>...
>...
>22:30 14 Customers
Assuming you only allow them to put in valid :15 minute data in the first
place:
$query = "select time_field, count(*) from booking GROUP BY time_field order
by time_field";
$bookings = mysql_query($query) or die(mysql_error());
while (list($time, $count) = mysql_fetch_row($bookings)){
echo "$time $count Customers<BR>\n";
}
The GROUP BY clause "smushes" all records with the same value in that field
together in a set so you can get the COUNT. Or AVERAGE on another field, or
MIN or MAX or all sorts of other cool "AGGREGATE" functions.
For example, the following might be a query you'd write to tell him which
hours are his biggest/lowest revenue-generators:
select time_field, min(bill), max(bill) from receipts group by time_field
Assuming that for each reservation he had recorded their bill in the first
place...