1

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.

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.

<?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>";
?>
4
  • what is your purpose of showing multiple select box? Commented May 22, 2016 at 10:11
  • I want that people can select more then 1 city. Commented May 22, 2016 at 10:16
  • Simple Use check box for this.Problem solved :) Commented May 22, 2016 at 10:18
  • The easiest way would be to use something like Bootstrap multiselect Commented May 22, 2016 at 10:46

1 Answer 1

1

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;
}
Sign up to request clarification or add additional context in comments.

10 Comments

Yes, for a couple of cities... Imagine how it would looks like with hundreds of cities :-)
yes you made me thinking @artur filipak.Any idea to help to implement this?
Please check this answer for jquery stackoverflow.com/questions/18421988/…
To which php file you want to send this value
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.