Jump to content

Mysql Query Count


mart94

Recommended Posts

Hi,

Im working on Top5 system, right. So i need help with this part: How to i get top results like, i have in table Country, and i need to get TOP5 of them, i mean like what Country are there most.

Example:

Country

Estonia

Estonia

Estonia

Russia

England

England

Then TOP will be so:

#1 Estonia

#2 England

#3 Russia

 

Hope you all understand and help me :)

 

All The Best:

Mart

Link to comment
Share on other sites

SELECT country, COUNT(*) AS countryCount FROM tableName GROUP BY Country ORDER BY countryCount DESC LIMIT 5

Hi, thanks for reply but i have still problems.

My code:

$c = mysql_query("SELECT country, COUNT(*) AS countryCount FROM TOP GROUP BY Country ORDER BY countryCount DESC LIMIT 5");
while($topc = mysql_fetch_assoc($c)){
$topcountry = $topc['country'];
echo $topcountry;
}

 

Result is coming out messed up, what im doing wrong?

All The Best:

Mart

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.