Jaesen Jaesen - 2 years ago 123
SQL Question

mysql php jquery hide show select

I know a little bit of PHP programming, but none of JQuery.
I have build a

dropdown menu with data from MySql db.
But now I want a button or something next to the
option, like a + sign or something that will give me a extra
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.

enter image description here

and then next you will get this.
enter image description here
And here is the code what I already have made.


$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>";

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download