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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.