【发布时间】:2016-08-13 15:39:09
【问题描述】:
表courses
courseID courseName
1 Diploma-Polytechnic
2 UG-Bachelor of Architecture (B.Arch)
3 UG-Bachelor of Engineering (B.E)
4 UG-Bachelor of Technology (B.Tech)
5 PG-Master of Architecture (M.Arch)
表branch
branchID courseID branchName
1 1 Civil Engineering
2 1 Computer Sci & Technology
3 1 Electrical Engineering
4 2 E&TC
5 2 Mechanical Engineering
以及我想要解决方案的代码,我已经能够获取第一个下拉列表的所有课程
<select name="courseName">
<option value="">Select Courses</option>
<?php $sql = "SELECT * FROM courses ";
$res = mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_assoc($res)) {
?>
<option value=""><?php echo $row['courseName']; ?></option>
<?php } ?>
</select>
第二个下拉列表保持为空,因为我想要这样的东西。
如果用户从第一个下拉列表中选择 1 门课程,则应自动从具有该相关课程的第二个下拉列表中的分支表中获取数据。如果他们是 IF 条件会更好
<select name="sDepartment">
<option value="">Department You Study</option>
<option value=""> </option></select>
例如,如果用户从第一个下拉列表中选择Diploma-Polytechnic of ID 1 那么第二个下拉列表应该有选项
Civil Engineering
Computer Sci & Technology
Electrical Engineering
如果可能,请提供与我的代码兼容的 JS/AJAX 代码。
【问题讨论】:
-
使用一些javascript。
-
你需要试试 Ajax。
-
您可以使用 Ajax 请求或获取不同下拉列表中的所有值并使用 JS 仅显示特定的值。
-
我不太了解 js 和 Ajax,但如果没有这两个就想要它,如果没有这两个就不可能,那么请提供与此兼容的 js/ajax
标签: php