Another solution is to and an onchange statment to the first dropdown that will reexecute the application populating the next dropdown with the filtered information. i.e.
// the first dropdown box you will populate on first execution leaving the default record null. This way the second dropdown is default empty.
$CSdbBld = $db->getCol("SELECT DISTINCT BuildingName FROM closet ORDER by BuildingName");
if ($CSdbBld == null) {
$CSdbmessage = "<h1>Record not found</h1>";
}
echo "<TR><TH bgcolor='#EEEEEE' class='FormLabel'>Building Name <I><SMALL>(building)</SMALL></i>";
//first dropdown starts here
$alen = count($CSdbBld);
When defining Option Group, add in a onchange statement. The example uses javascript to reload the page. I could not find a way to do this with PHP.
echo "<SELECT name='building' onchange=\"this.form.submit();\">";
echo "<OPTGROUP label='Building Name'>";
echo "<OPTION value=''> </OPTION>";
for($i=0; $i <= $alen - 1; $i++){
if ($CSdbBld[$i] == $building) {
echo "<OPTION selected value='$CSdbBld[$i]'> $CSdbBld[$i]</OPTION>";
}else {
echo "<OPTION value='$CSdbBld[$i]'> $CSdbBld[$i]</OPTION>";
}
}
echo "</OPTGROUP>";
echo "</SELECT>";
//Test end
The second dropdown will auto fill based on the value of the first. Once the first is set the application will re-run and populate the second.
echo "</TH>";
$CSdbCl = $db->getCol("SELECT DISTINCT ClosetNumber FROM closet
WHERE closet.BuildingName ='$building' ORDER by ClosetNumber");
if ($CSdbCl == null) {
$CSdbmessage = "<h1>Record not found</h1>";
}
echo "<TH bgcolor='#EEEEEE' class='FormLabel'>Closet Number <I><SMALL>(closet)</SMALL></i>)";
I just created a function to do the dropdown. The code is the same as the one above.
DropDown($CSdbCl, "closet", $closet, "Closet Number");