Reputation: 28
I know a little bit of PHP programming, but none of JQuery.
I have build a <select>
dropdown menu with data from MySql db.
But now I want a button or something next to the <select>
option, like a + sign or something that will give me a extra <select>
option. And that this can come as many time as you want.
Ps. I'm sorry for my English.
Here is a picture of how I want this to be.
and then next you will get this. And here is the code what I already have made.
<?php
$conn = new mysqli('localhost', 'username', 'password', 'database')
or die ('Cannot connect to db');
$result = $conn->query("select id, name from table");
echo "<html>";
echo "<body>";
echo "<select name='id'>";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['name'];
echo '<option value="'.$id.'">'.$name.'</option>';
}
echo "</select>";
echo "</body>";
echo "</html>";
?>
Upvotes: 1
Views: 670
Reputation: 458
You can use check box instead of dropdown for multiple selection
while ($row = $result->fetch_assoc()) {
unset($id, $name);//use if you want
$id = $row['id'];
$name = $row['name'];
echo '<input name="city[]" type="checkbox" value="'.$name.'" />'.$name;
}
Upvotes: 1