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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 9, 2010 Share Posted January 9, 2010 What do you mean by 'messed up' ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.