php - 从数组生成值到下拉列表
问题描述
所以我想根据学生的大学只显示特定的课程,这些课程将来自某个数组,而不是仅仅列出所有课程......我想我有点明白逻辑,但课程没有显示。
这是我的代码:
<div class="student_reg">
<form action = "registration.php" method="post">
<input type="text" name="sn" placeholder="Student Number"><br>
<input type="text" name="fname" placeholder="Firstname"><br>
<input type="text" name="lname" placeholder="Lastname"><br>
<input type="text" name="age" placeholder="Age"><br>
<input type="password" name="pass" placeholder="Password"><br>
<input type="password" name="pass2" placeholder="Confirm Password"><br><br>
<textarea rows = "5" cols = "30" placeholder="Address" name = "address"></textarea><br><br>
<label>Year Level</label>
<select name = "yearLevel">
<option>1st</option>
<option>2nd</option>
<option>3rd</option>
<option>4th</option>
<option>5th</option>
</select><br><br>
<select name = "college">
<option value = "">College</option>
<option>College of Engineering</option>
<option>College of Fine Arts, Architecture and Design</option>
</select><br><br>
<?php
$cengr = array("BSME", "BSECE", "BSCpE", "BSIE", "BSCE");
$cfad = array("BSA", "BSID", "BFA Painting", "BFA Visual Com", " Multimedia Arts");
?>
<select name = 'course'>
<option value = "">Course</option>
<?php
if(isset($_POST['college'])){
if($_POST['college'] == "College of Engineering"){
foreach($cengr as $course => $value){
echo "<option value =".$course.">".$value."</option>";
}
}
if($_POST['college'] == "College of Fine Arts, Architecture and Design"){
foreach($cfad as $course => $value){
echo "<option value =".$course.">".$value."</option>";
}
}
}
?>
</select>
</form>
</div>
解决方案
推荐阅读
- php - PHP中的倒计时数字数组
- laravel - 迁移命令错误:Illuminate\Database\QueryException:在 sql server 上找不到驱动程序
- mockito - 模拟连续呼叫的不同响应
- react-native - Apollo setContext 无法从服务器保存令牌
- c# - 如何让 ASP.NET Core DI 获得 Simple Injector 解决的依赖关系?
- python - 我无法在 OpenCV 中打开图像
- typescript - 在 TypeScript 中,如何在调用语句后表示非空条件为真?
- javascript - For 循环仅在数组参数上运行一次
- node.js - 如何完全不响应使用 koa 2 的请求?
- php - 如何在同一个一键调用中插入和更新不同表中的sql数据库