Hi Guys
I have two drop down boxes on a form, each one calls in fields from different tables in my db. I call these fields in dynamically, using the following code:
//user a dropdown to select all the modules
$query = "SELECT module_id, name FROM module";
$data = mysqli_query($dbc, $query);
$options="";
while ($row=mysqli_fetch_array($data)) {
$module_id=$row["module_id"];
$name=$row["name"];
//by posting the subject_name into the module table, this code will insert the actual subject_id into the fk subject_id field
$options.="<option value= \"$module_id\">".$name."</option>";
}
//user dropdown for student
$query = "SELECT student_id, first_name, surname FROM student";
$data = mysqli_query($dbc, $query);
$options="";
while ($row=mysqli_fetch_array($data)) {
$student_id=$row["student_id"];
$first_name=$row["first_name"];
$surname=$row["surname"];
//by posting the subject_name into the module table, this code will insert the actual subject_id into the fk subject_id field
$options.="<option value= \"$student_id\">".$first_name." ".$surname."</option>";
}
So one drop down should show a list of modules and one drop down should show a list of students.
When i run this code I don't get an error, but both drop down boxes are populated with the same Student table attributes. Is this because I am using two WHILE loops and it takes the values of the latest one? Could anyone help me with how I get the drop down boxes to display the appropriate attributes from the two tables?
I then want to insert the selected fields into another table, but I know how to do this, just not sure how to populate the seperate drop downs.
Thanks a lot for your time. Really appreciate it.