<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Adventure Recommender</title>
    <link href="adventure.css" type="text/css" rel="stylesheet" />
  </head>

  <body>
    <h1>Adventure Recommender</h1>

    <p>
            Welcome to the Adventure Recommender -- the web site for discriminating
            traveller needing ideas!  Choose the demographics of a place you'd like
            to visit and we'll recommend countries for you to adventure to!
    </p>

    <form action="adventure_recommendations.php" method="get">
        <div>
            <h2>Which continents do you prefer to travel to?</h2>

            <select name="continents[]" size="4" multiple="">
                <option value="Anywhere" selected="selected">Anywhere</option>
                <?php print_continent_options(); ?>
            </select>
        </div>

        <div>
        <h2>Which language(s) do prefer to be spoken?</h2>

            <select name="languages[]" size="12" multiple="">
                <option value="Any Language" selected="selected">Any Language</option>
                <?php print_language_options(); ?>
            </select>
        </div>

        <div>
            <h2>Do you prefer a developed or undeveloped country?</h2>

            <input type="radio" name="economy" value="developed" /> Developed
            <input type="radio" name="economy" value="developing" /> Developing
            <input type="radio" name="economy" value="any" checked="checked" /> Don't Mind
        </div>

        <div>
            <input type="submit" value="Submit" />
        </div>
    </form>
  </body>
</html>

<?php

function print_continent_options() {
    $db = mysql_connect("webster.cs.washington.edu", "jkmiller", "9v3nTBWiL2eBC");
    mysql_select_db("world");

    $query = "SELECT DISTINCT continent
              FROM Countries";
    $results = mysql_query($query);

    while ($row = mysql_fetch_array($results)) {
        $continent = $row["continent"];

        print("<option value=\"$continent\">$continent</option>");
    }

    mysql_free_result($results);
    mysql_close($db);
}

function print_language_options() {
    $db = mysql_connect("webster.cs.washington.edu", "jkmiller", "9v3nTBWiL2eBC");
    mysql_select_db("world");

    $query = "SELECT DISTINCT language
              FROM CountriesLanguages
              WHERE official = 'T'
                AND percentage > 90
              ORDER BY language";
    $results = mysql_query($query);

    while ($row = mysql_fetch_array($results)) {
        $language = $row["language"];

        print("<option value=\"$language\">$language</option>");
    }

    mysql_free_result($results);
    mysql_close($db);
}

?>
