-2

How to solve if i select one Value form dropdown. Biside I have another drop down and its values should be auto Updated According to Option I have selected from first dropdown ?

1 Answers1

0

you can try to generate a lookup table whenever you create a drop-down list:

 function createDropdown(&$ddlLookup) {
 echo '<select multiple name="items[]">';
    try {
        $items = mysql_query("SELECT item_id,item_type FROM items");
        while ($row = mysql_fetch_assoc($items)) {
            echo '<option value="'.$row['item_type'].'"';
            echo '>'. $row['item_type'] . '</option>'."\n";
            $ddlLookup[$item_type] = $item_id;
        }
    }
    catch(PDOException $e) {
        echo 'No results';
    }
 echo '</select>';
 }

Then whenever you need the id for a given description you use that table(array) to get it:

   $mainDropdownLUT = array();
   createDropdown($mainDropdownLUT);

var_dump($mainDropdownLUT['testCow']);
 -> 734

Also, if you need to pass it to another page it can be serialized and added to a hidden field.

 $mainDropdownLUT = serialize($mainDropdownLUT);
 "<input type="hidden" value =\"$mainDropdownLUT\">"
 -------------------------**OTHER PAGE **--------------
  $mainDropdownLUT = unserialize($mainDropdownLUT);
Abi
  • 724
  • 6
  • 22