I would like to create a multi-select drop down list of countries in my form which lets users choose more than one country and also provides the ability to remove the item they selected, if needed.
I could create a drop down list which extracts the name of the countries from a mysql table, but it lets users only select one country. I searched a lot for multi-select drop down but none of the samples that I have found get data from mysql. They had only a few options which could easily write with option value like How to access the values selected in the multiselect dropdown list in PHP?
This is my code through which only one item can be selected:
<?php
mysql_connect('localhost', 'root', 'password');
mysql_select_db('imdb');
$sql2 = "SELECT country FROM countries";
$result2 = mysql_query($sql2);
echo "<select name='country'>";
while ($row = mysql_fetch_array($result2)) {
echo "<option value='" . $row['country'] . "'>" . $row['country'] . "</option>";
}
echo "</select>";
?>
<select name="country" multiple>You browser couldn't care less where the options in the select came from. it just sees html.