目前,我在下面完成的代码是仅显示分配了tutor_id的课程的代码。但是,我想要的是显示未分配tutor_id的课程以及“没有为此课程分配辅导员”。 Tutor_id是数据库中的NULL变量。
(存储在导航页面中)
$arrItems = executeSelectQuery("SELECT * FROM course, category, tutor WHERE course.Category_id = category.Category_id AND course.Tutor_id = tutor.Tutor_id");
$totalDesign = executeSelectQuery("SELECT * FROM course, category, tutor WHERE course.Category_id = category.Category_id AND course.Tutor_id = tutor.Tutor_id");
$numrows = count($totalDesign);
$arrItems = executeSelectQuery("SELECT * FROM course, category, tutor WHERE course.Category_id = category.Category_id AND course.Tutor_id = tutor.Tutor_id ORDER BY course.Course_name ASC LIMIT $offset, $rowsPerPage");
答案 0 :(得分:0)
试试
SELECT * FROM course, category, tutor WHERE course.Category_id = category.Category_id AND ( course.Tutor_id = tutor.Tutor_id OR course.Tutor_id IS NULL )
答案 1 :(得分:0)
要获得单独的非导师课程列表:
$arrItems = executeSelectQuery("SELECT * FROM course WHERE Tutor_id is NULL");
答案 2 :(得分:0)
SELECT * FROM course
INNER JOIN category ON course.Category_id = category.Category_id
OUTER JOIN tutor ON course.Tutor_id = tutor.Tutor_id
ORDER BY course.Course_name ASC LIMIT $offset, $rowsPerPage
外部联接提供您所追求的功能。所有 将选择一些包含空值的课程 Tutor_id字段。确定代码何时发生并打印 “在这些场合,没有指导过这门课程的导师”。