0

I have a mySQL database, and I have the option that it displays all the 'Treatments' as a dropdown box on my html page. How would I go about implementing the code, so that if the user wants to select more than one treatment, another dropdown box will appear?

EDIT: e.g. Lets say you are shopping for some items online, and you have all the items listen in a dropdown box. You pick one, and then you want to pick more. So you click: 'add more' and another dropdown appears on the page where you can select another item.

Here is the PHP code:

<?php

$hostname = 'hostname';
$dbname = 'dbname';
$username = 'username';
$password = 'password';

$con=mysql_connect($hostname,$username,$password,$dbname) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db($dbname,$con) or die("Failed to connect to MySQL: " . mysql_error());


$query = "SELECT * FROM `Treatments`";

$result = mysql_query($query, $con);
$options = "";

if (!$result){
    die("No results found.");
}

while ($row = mysql_fetch_array($result)){
    $options .= "<option>$row[1]</option>";
}


?>
Filip Grebowski
  • 391
  • 5
  • 22

1 Answers1

0

Actually you need to make multiselect drop down. If you add multiple = "multiple" HTML tag then drop down will be used as a multi select.

<select name="anyName[]" multiple>
  <?php
  while ($row = mysql_fetch_array($result)){
    echo "<option>$row[1]</option>";
 }
 ?>
</select>

For more help you will need to look this link. jQuery multiselect drop down menu

Hope It will help you.

Thanks

Community
  • 1
  • 1