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
https://forums.phpfreaks.com/topic/187832-mysql-query-count/
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
https://forums.phpfreaks.com/topic/187832-mysql-query-count/#findComment-991718
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.