I have two select on my form the first get all its elements from a table named "department" in my school database.
It is working no problem, but my question is how to make the second select option box receive elements coming from the table "class" having column "departmentid" which is equal to the selected department in the first select option I mean if the user selects department "IT" the second select option may bring classes"4,5,6" because they were registered with the ID of that department.
The reason i am doing this is because all the departments don't have the same classes, It would be great if this event occured after clicking on the first select option.
My Database name is "School" Table1 "departments" with its columns "Departmentid,Name" Table2 "Class" with its columns "classid,level,Departmentid"
//First Select Option
<select class="form-control">
<option selected="selected">Show All Departments</option>
<?php
$link = mysqli_connect("localhost", "root", "", "school");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());}
$con="SELECT * FROM departments";
$query_test = mysqli_query($link,$con) or die ("MySQL error: " .mysqli_error($link) ." Query: $query");
while($row=mysqli_fetch_array($query_test))
{
$result=$row['Name'];
$results=$row['Departmentid'];
?>
<option name="find"value="<?php echo $row['Name'];?>"><?php echo $row['Name'];?></option>
<?php
}
?>
</select>
//Second select option
<select class="form-control">
<option selected="selected">Show All Classes</option>
//Input those classes in this select option
<option> </Option>
</select>