Jump to content

How to do a Category count from MySQL


project18726

Recommended Posts

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 (8)

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.