Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Statistics of Countries

    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.

    PHP Code:
    $q $database->query("SELECT `country` FROM `members`");
    $country $database->count_rows($q);
    if (
    $country >= 1) {
        while (
    $r $database->fetch_row($q)) {
            
    $r["country"]
        }

    Last edited by afdah; 12-31-2011 at 02:55 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,919
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    Use this query:
    Code:
    SELECT country, COUNT(*) AS memberCount
    FROM members 
    GROUP BY country 
    ORDER BY memberCount DESC
    LIMIT 5
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    afdah (12-31-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •