我在下面有一个基本的 mysqli 代码,它执行查询以从数据库中选择 CourseId 和 Course Name 并将其显示在下拉菜单中。
$sql = "SELECT CourseId, CourseName FROM Course ORDER BY CourseId";
$sqlstmt=$mysqli->prepare($sql);
$sqlstmt->execute();
$sqlstmt->bind_result($dbCourseId, $dbCourseName);
$courses = array(); // easier if you don't use generic names for data
$courseHTML = "";
$courseHTML .= '<select name="courses" id="coursesDrop" onchange="getModules();">'.PHP_EOL;
$courseHTML .= '<option value="">Please Select</option>'.PHP_EOL;
while($sqlstmt->fetch())
{
$course = $dbCourseId;
$coursename = $dbCourseName;
$courseHTML .= "<option value='".$course."'>" . $course . " - " . $coursename . "</option>".PHP_EOL;
$outputcourse = "";
$outputcourse .= "<p><strong>Course:</strong> " . $course . " - " . $coursename . "</p>";
}
$courseHTML .= '</select>';
现在让我们说下拉菜单包含以下这些课程:
INFO101 - Information Communication Technology
INFO102 - Computing
出于某种奇怪的原因,无论我选择哪门课程,它总是INFO102 - Computing
在下拉菜单下方回显 CourseId 和 CourseName。为什么是这样?