project18726 Posted September 23, 2008 Share Posted September 23, 2008 Hi all, I'm throwing together a invoice database for a local company. They want their customers to to be able to retrieve past orders on their website via a login section. I can dso all that -- it's all pretty straight forward. However, I'm puzzled when it comes to counting the records. I am listing the past orders by month and so far that is working for me. It starts with the current month and then lists backwards until the creation date of the account. It looks like this... 2008 September August July June May April March February January 2007 December November October .......... And so on and so on. What I'd like to do is to be able to display how many invoices a customer has in a given month, at a glance. So it would look something like this... 2008 September (4) August (1) July ( June (3) May (3) April (0) March (6) February (0) January (0) 2007 December (2) November (2) October (0) .......... I can get it done but I would end up making a SELECT statement to count the rows per month for every month, and some of these customers have been with the company for over 60 months. I know that running some-60 queries everytime a customer loads their page would be downright abuse on the server. There has got to be an easier way. I looked into the count() function but didn't quite understand it. My "orders" table has the following fields: order_id, customer_id, invoice_date, invoice_number, po_number, conf_number, and certs_location. The invoice_date field is a DATE type. Any ideas? Link to comment https://forums.phpfreaks.com/topic/125386-how-to-do-a-category-count-from-mysql/ Share on other sites More sharing options...
F1Fan Posted September 23, 2008 Share Posted September 23, 2008 Something like: SELECT count(order_id), invoice_date FROM orders WHERE customer_id = $id GROUP BY invoice_date Link to comment https://forums.phpfreaks.com/topic/125386-how-to-do-a-category-count-from-mysql/#findComment-648254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.