Jump to content

[ resolved ] PHP Count top 3


CanMan2004

Recommended Posts

Hi all

I have a sql table which looks like

ID    NAME
1    Dave
2    John
3    Dave
4    Sarah
5    Sarah
6    John
7    Sarah
8    Dave
9    Henry
10    Sarah

As you will notice

Sarah is listed 4 times
Dave is listed 3 times
John is listed 2 times
Henry is listed 1 time

As im adding to this list, what I want to do is to display the top 3 most popular names, by doing a query which would return the most popular to the least popular but just showing the top 3.
The result would look something like

Sarah - 4
Dave  - 3
John  -  2

I use the following query

[code]$sql = "SELECT * FROM people";[/code]

But I cant figure out how to tweak it to do the above. Can anyone help?

Thanks in advance

Dave
Link to comment
https://forums.phpfreaks.com/topic/30176-resolved-php-count-top-3/
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.