Automatic population of second drop down from mysql
Posted: Sun Mar 12, 2006 9:58 am
Hi,
I've got three tables, one with teachers information in, one with lesson types in and one with which teacher performs which lesson. This information is returned in two recordsets:
These recordset are then displayed in two drop down menus, one displaying teacher and one the lessons, like so:
Currently these have no relation and i would like it so the options displayed in the second drop down menu are dependent on the teacher selected in the first. So you would only get the lessons that the teacher teaches in the second drop down. I've look on the net and the examples ive found dont really suit my problem.
Can anyone help?
Thanks,
Rob
I've got three tables, one with teachers information in, one with lesson types in and one with which teacher performs which lesson. This information is returned in two recordsets:
Code: Select all
//returns the teachers for teachers menu
$query_teachermenu = "SELECT teacherid, teacher_name FROM teacher WHERE cancelled = 'N'";
$teachermenu = mysql_query($query_teachermenu, $connection) or die(mysql_error());
$row_teachermenu = mysql_fetch_assoc($teachermenu);
$totalRows_teachermenu = mysql_num_rows($teachermenu);
//returns the lessonsid and lessons name for lessons menu
$query_lessontypes = "SELECT * FROM teacherslessons, lessontype WHERE teacherslessons.lessontypeid = lessontype.lessontypeid";
$lessontypes = mysql_query($query_lessontypes, $connection) or die(mysql_error());
$row_lessontypes = mysql_fetch_assoc($lessontypes);
$totalRows_lessontypes = mysql_num_rows($lessontypes);Code: Select all
<form method="post" name="form1">
<select name="teacherid">
<?php
do {
?>
<option value="<?php echo $row_teachermenu['teacherid']?>" ><?php echo $row_teachermenu['teacher_name']?></option>
<?php
} while ($row_teachermenu = mysql_fetch_assoc($teachermenu));
?>
</select>
</div></td>
<tr>
<tr valign="baseline">
<td nowrap align="right"><div align="left">Lesson:</div></td>
<td><div align="left">
<select name="lessontypeid">
<?php
do {
?>
<option value="<?php echo $row_lessontypes['lessontypeid']?>" ><?php echo $row_lessontypes['lessontype_name']?></option>
<?php
} while ($row_lessontypes = mysql_fetch_assoc($lessontypes));
?>
</select>
</form>Can anyone help?
Thanks,
Rob