0
下面我有一個可以成功工作的mysqli查詢;它不會輸出成功消息中的所有變量
$courseid = (isset($_POST['courses'])) ? $_POST['courses'] : '';
$moduleid = (isset($_POST['moduleid'])) ? $_POST['moduleid'] : '';
$moduleno = (isset($_POST['moduleno'])) ? $_POST['moduleno'] : '';
$modulename = (isset($_POST['modulename'])) ? $_POST['modulename'] : '';
$query = "SELECT cm.CourseId, CourseNo, CourseName, cm.ModuleId
FROM Course c
INNER JOIN Course_Module cm
ON
c.CourseId = cm.CourseId
JOIN Module m
ON
cm.ModuleId = m.ModuleId
WHERE cm.CourseId = ? AND cm.ModuleId = ?";
// prepare query
$stmt=$mysqli->prepare($query);
// You only need to call bind_param once
$stmt->bind_param("ii", $courseid, $moduleid);
// execute query
$stmt->execute();
// get result and assign variables (prefix with db)
$stmt->bind_result($dbCourseId, $dbCourseNo, $dbCourseName, $dbModuleId);
//get number of rows
$stmt->store_result();
$numrows = $stmt->num_rows();
我得到的問題是在我的成功消息。它能夠輸出$moduleno
和$modulename
變量,但它不會在成功消息中輸出$dbCourseNo
和$dbCourseName
變量。爲什麼是這樣?
if ($numrows == 1){
echo "<span style='color: green'>The following Module has been added into Course:" . $dbCourseNo . " - " . $dbCourseName . ":<br/>" . $moduleno . " - " . $modulename . "</span>";
}
嘗試更明確哪些表的列是從哪裏來的?例如'cm.CourseNo,cm.CourseName' –
@GigaWatt是的,但CourseNo和CourseName只在課程表中。 – user1881090