SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Want to list countries and regions

    I have a table of users with regions and countries for every user.
    Now I would like to echo a list of all countries I have in every region.

    Something like this:
    EUROPE
    France
    Germany
    Norway
    Spain
    Sweden

    SOUTH AMERICA
    Argentina
    Brasil
    Chile

    NORTH AMERICA
    Canada
    USA

    I tried the following, but it's not working. What do I need to add/change in this?
    PHP Code:
    SELECT DISTINCT continent FROM station_db ORDER BY country DESC;

    <p><?php do { ?><?php echo $row_rs_countrylist['continent']; ?><?php echo $row_rs_countrylist['country']; ?></p>
    <?php } while ($row_rs_countrylist mysql_fetch_assoc($rs_countrylist)); ?>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,491
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    1) add the country column to the SELECT of your query (you can't display what you didn't get from the database...)
    2) use a while loop instead of a do-while loop (you have to fetch the first row before you display the data)
    3) use the mysqli_ or pdo extensions instead of mysql, because the mysql_ extension has been deprecated in PHP 5.5.0 and will be removed completely in the future.

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ok, I have to look that up. I'm using Dreamweaver and it makes the code. I just modify it.
    And it seems like DW isn't using mysqli... I keep forgetting about that...
    So, I'm not sure about all the stuff you write... but I can Google it I guess.

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hmmm, I'm not sure how to make the query. What would it look like to get all the countries and continents, but group them by continent?


Bookmarks

Posting Permissions

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