Jump to content

Best Way To Count Records By Field


tail

Recommended Posts

I have a table with a field named "categories". What would be the best way to count all of the records with a certain category? Should I use COUNT for each category or is there a better solution so I don't query the database so many times?

 

Ex:

id        name        category

1        sample        cat1

2        sample2      cat2

3        sample3      cat1

4        sample4      cat1

5        sample5      cat2

 

 

Result:

Cat1: 3

Cat2: 2

Link to comment
https://forums.phpfreaks.com/topic/149608-best-way-to-count-records-by-field/
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.