mart94 Posted January 9, 2010 Share Posted January 9, 2010 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 More sharing options...
Mchl Posted January 9, 2010 Share Posted January 9, 2010 SELECT country, COUNT(*) AS countryCount FROM tableName GROUP BY Country ORDER BY countryCount DESC LIMIT 5 Link to comment https://forums.phpfreaks.com/topic/187832-mysql-query-count/#findComment-991716 Share on other sites More sharing options...
mart94 Posted January 9, 2010 Author Share Posted January 9, 2010 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 More sharing options...
Mchl Posted January 9, 2010 Share Posted January 9, 2010 What do you mean by 'messed up' ? Link to comment https://forums.phpfreaks.com/topic/187832-mysql-query-count/#findComment-991720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.