Hi,
I’m trying to select countries from database and present them in a select box.
I managed to do that, but I don’t want the countries that have already been selected to show up again (that is, I want to avoid duplicate values).
I tried using array_unique but couldn’t get it.
Is there another way to do this?
Thanks in advance…
<select name="country">
<?php
include ('connection2host.php');
$get_country = mysql_query("SELECT country FROM mainweb WHERE who='host'");
while ($row = mysql_fetch_array($get_country)){
$country = $row['country'];
echo '<option value="'.$country.'">'.$country.'</option>';
}
?>
</select>
If you absolutely had to do it the PHP/Array then you would have an existing countries array, and check if the current country is in that array and if not then add it.
However AnthonySterling’s method is much better, general rule of thumb, if you’re doing something with PHP that can be done with SQL, SQL is usually the faster way to do it.
it’s written alright, but if the document is saved as .html than the select box is very narrow and empty.
If the document is saved as .php than it works.
I need it in .html if possible since all my links are leading to .html