Have a look at this
<?php
$query=do_query("SELECT company FROM `suppliers`");
while(list($company)=mysql_fetch_row($query))
{
$query=do_query("SELECT ref,productname,modelnumber,ordered_ph,instock,minstock FROM `".$company."`");
while(list($ref,$product,$model,$ordered,$instock,$minstock)=mysql_fetch_row($query))
{
$array .="\"".$company."\",\"".$model." - ". $product."\",\"".$ref."\",\"".$ordered."\",\"".$instock."\",\"".$minstock."\",";
}
}
$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/6; i++) {
if (supplier_toCategoryMap[i*6] == manCode) {
category.options.length = j+1;
category.options[j].value = supplier_toCategoryMap[i*6+2];
category.options[j].text = supplier_toCategoryMap[i*6+1];
j += 1;
}
}
return;
}
</script>
<div class="content" align="center">
<table width="40%" align="center">
<?if (!empty($_SESSION['error']))
{
echo "<a href=discrepancy.php target=_blank>Discrepancy list</a>";
}
?>
<form name="stockupdate" method="post" action="<?echo $_SERVER['PHP_SELF'];?>?what=stock&page=add">
<tr><td align="right">Choose a supplier</td><td><select name="supplier" class="textbox" onChange="supplier_popCategory(this, this.form.category)">
<option value="" selected>Please choose</option>
<?
$query=do_query("SELECT company FROM `suppliers`");
while(list($company)=mysql_fetch_row($query))
{
echo "<option value=\"$company\">$company</option>\n";
}
?>
</select></td></tr>
OK - all you have to do is populate the first array with what you want...
If in each array part there is are two sections.. (easiest):
1) Make the array like Select1, item1, Select1, item2, Select1, item3, Select2, item1
get the idea ?
OK - now you can set the items in the first select box from the database, ensuring that the value is the same as the first part in each of the array parts.
In the javascript code - mine is set for 6 sections - so change every occurence of 6 to 2....
voila...
Now all you have to do is comment and understand it !!!