Jump to content

Simple "COUNT" help


Crooked

Recommended Posts

Hey guys,

 

I'm currently trying to count how many of the same kind of "id" there is in a certain table and then it should print out the rows by either ASC or DESC starting or ending on the highest/lowest.

 

 

To understand it better:

 

I have a table where i have 2 different types of rows ( cake / cofee )

 

In the "cake" row it could possibly be something like -

Cake - row

1

1

1

1

1

2

2

 

i want help with how i can do a COUNT on how many number 1 there is and how many number 2 there is and etc to about 5, and then have em print out the cakes name from the highest bought one to the lowest one.

 

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/233509-simple-count-help/
Share on other sites

To get counts per group you need to do a GROUP BY on the column that has the type ID's.  I have no idea what your table structure looks like, but something like this:

 


SELECT COUNT(*) as countof, rowtype FROM cake GROUP BY rowtype ORDER BY countof DESC LIMIT 5

Link to comment
https://forums.phpfreaks.com/topic/233509-simple-count-help/#findComment-1200691
Share on other sites

here is a image of what i was trying to get to:

 

countproblem.jpg

 

and forget about the cofee table.

 

So simple put i wanted to make a hit-list or top-list of a sort because i havn't gotten around to get familier with the count that much.

 

 

(FYI this is a example i quickly threw together, i left the original files on my laptop which is at home)

 

 

Link to comment
https://forums.phpfreaks.com/topic/233509-simple-count-help/#findComment-1200704
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.