我的数据库中有两列:faculty
和department
。我设法将数据绑定到包含faculties
的下拉列表。但对于department
到foreign key
的{{1}},如何添加新的并在下拉菜单中显示?
基本上,我需要在第一个下拉列表中选择faculty
时,第二个下拉菜单中会显示faculty
departments
,我可以如果我愿意,可以向选定的教师添加另一个部门。我如何实现这一目标?
faculty
答案 0 :(得分:1)
请使用if condition或动态查询:
$query = '';
if (isset($_POST['save_department'])) {
$query = "INSERT INTO department (name) VALUES ('" .
$_POST["department_name"] . "')";
}else{
$query = "SELECT name, faculty_id, department_ID FROM department ORDER BY name ASC";
}
$result = mysqli_query($con, $query);