I have a basic mysqli code below where it performs a query to select CourseId and Course Name from database and display it in a drop down menu.
$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>';
Now lets say the drop down menu contains these courses below:
INFO101 - Information Communication Technology
INFO102 - Computing
For some strange reason no matter which course I choose, it always echos the CourseId and CourseName INFO102 - Computing underneath the drop down menu. Why is this?
<p><strong>Course:</strong>.....</p>This may be causing the problem,because I don’t think its valid to have tags other than
<option></option>inside a<select></select>tag.Try removing those stuff and see if the output appears in drop down.