It is possible to do - but with Javascript not PHP...
However you can get it to work....
Have a look at this....
$query=do_query("SELECT company,category FROM suppliers");
while(list($company,$category)=mysql_fetch_row($query))
{
$category=explode("\n",$category);
foreach($category as $string)
{
$string=trim($string);
$array .="\"".$company."\",\"".$string."\",";
}
}
$array=substr($array,0,-1);
?>
<script language="JavaScript">
var supplier_toCategoryMap = new Array(
<? echo $array;?>);
function supplier_popCategory(supplier, category) {
var manCode = supplier.options[supplier.selectedIndex].value;
var i, j;
j = category.options.length = 1;
category.options.selectedIndex = 0;
for(i=0; i<supplier_toCategoryMap.length/2; i++) {
if (supplier_toCategoryMap[i*2] == manCode) {
category.options.length = j+1;
category.options[j].value = supplier_toCategoryMap[i*2+1];
category.options[j].text = supplier_toCategoryMap[i*2+1];
j += 1;
}
}
return;
}
That bit sets up the initial array for the boxes - and associates which items should be shown in the second box with those shown in the first dropdown
array looks like ("box1","Item 1","box1","item 2","box1","item 3","box2","Item 4","box2","item 5")
Then this
<select name=\"supplier\" onChange=\"supplier_popCategory(this, this.form.category)\" class=\"textbox\">
<option value=\"\" selected>Please Choose</option>");
$query=do_query("SELECT company FROM suppliers");
while(list($company)=mysql_fetch_row($query))
{
print("<option value=\"$company\">$company</option>
");
}
?>
</select>
Shows the main select box to choose the initial choice
and this
<select name=\"category\" class=\"textbox\"><option value=\"\" selected>Please Choose</option></select>
Is the dynamically created dropdown select box...
Hope it helps....