View Full Version : Resolved Statistics of Countries

12-31-2011, 03:29 AM
Hi, I have a database table named 'members'.
1 of the column in the table members is named 'country'.

This is what I intend to do.
I want to make use of the data in 'country' to calculate the popularity of the country.

I want to show what are the top 5 countries are.
I have got something like the code below to start with but I am stuck with $r["country"] as I do not know what to do with the data to achieve my goal.

$r["country"] contains 2 character of the country abbreviation.

Inputs required.
Thank you.

$q = $database->query("SELECT `country` FROM `members`");
$country = $database->count_rows($q);
if ($country >= 1) {
while ($r = $database->fetch_row($q)) {

Old Pedant
12-31-2011, 07:22 AM
Use this query:

SELECT country, COUNT(*) AS memberCount
FROM members
GROUP BY country
ORDER BY memberCount DESC