<?php
include("top.html");
include("shared.php");
$languages = "'" . implode("', '", $_REQUEST["languages"]) . "'";
$countries_query = "SELECT DISTINCT c.name
                    FROM countries c
                    JOIN languages l ON c.code = l.country_code
                    WHERE c.continent = '" . $_REQUEST["continent"] . "'
                          AND l.language IN ($languages)
                          AND l.official = 'T'
                          AND (((c.gnp * 1000000) / c.population) < 10000
                          OR c.life_expectancy < 70)
                    ORDER BY c.name";
$rows = perform_query($countries_query);
if ($rows) { ?>

    <h2>Countries that fit your preferences for your next adventure are:</h2>
    <ul>
      <?php foreach ($rows as $row) { ?>
        <li><?= $row["name"] ?></li>
      <?php } ?>
    </ul>

<?php } else { ?>
    <p>Sorry, there were no countries matching your preferences.</p>
<?php } ?>

  </body>
</html>
