簡體   English   中英

MYSQL語句無法找出問題所在

[英]MYSQL statement can't figure out whats wrong

我已經為學生時間表打印輸出創建了這個加入語句,我是sql和php的新手,無法弄清楚我做錯了什么。 如果有人能幫助我,我將不勝感激..在此先感謝...(請注意,如果這是一個非常基本的問題,則...)

mysql_select_db($database_newconn, $newconn);
$query_Recordset1 = "SELECT a.student_id AS "Student ID", f.name AS "Course Name", g.name AS "Lesson Name", g.date AS "Lesson Date", g.start_time AS "Lesson Start Time", g.end_time AS "Lesson End Time", CONCAT( h.first_name,' ', h.last_name) AS "Lesson Tutor" FROM student_table a JOIN enrollement_schedule_table b ON(a.id = b.student_id) JOIN course_table f ON(f.id = b.course_id) JOIN student_attendance_slot_table c ON(c.student_id = a.id) JOIN lesson_table g ON(g.id = c.lesson_id) JOIN tutor_table d ON(d.id = g.tutor_id) JOIN staff_table h ON(h.id = d.staff_id)";
$Recordset1 = mysql_query($query_Recordset1, $newconn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

您有報價問題。 消除列別名周圍的引號,並使用刻度線

$query_Recordset1 = "
    SELECT a.student_id AS `Student ID`, 
        f.name AS `Course Name`, 
        g.name AS `Lesson Name`, 
        g.date AS `Lesson Date`, 
        g.start_time AS `Lesson Start Time`, 
        g.end_time AS `Lesson End Time`, 
        CONCAT( h.first_name,' ', h.last_name) AS `Lesson Tutor` 
        FROM student_table a 
        JOIN enrollement_schedule_table b ON(a.id = b.student_id) 
        JOIN course_table f ON(f.id = b.course_id) 
        JOIN student_attendance_slot_table c ON(c.student_id = a.id) 
        JOIN lesson_table g ON(g.id = c.lesson_id) 
        JOIN tutor_table d ON(d.id = g.tutor_id) 
        JOIN staff_table h ON(h.id = d.staff_id)";

您需要在查詢中的字段上使用反引號而不是雙引號。 檢查一下:

SELECT 
a.student_id AS `Student ID`
, f.name AS `Course Name`
, g.name AS `Lesson Name`
, g.date AS `Lesson Date`
, g.start_time AS `Lesson Start Time`
, g.end_time AS `Lesson End Time`
, CONCAT(h.first_name, ' ', h.last_name) AS `Lesson Tutor` 
FROM
student_table a 
JOIN enrollement_schedule_table b 
ON (a.id = b.student_id) 
JOIN course_table f 
ON (f.id = b.course_id) 
JOIN student_attendance_slot_table c 
ON (c.student_id = a.id) 
JOIN lesson_table g 
ON (g.id = c.lesson_id) 
JOIN tutor_table d 
ON (d.id = g.tutor_id) 
JOIN staff_table h 
ON (h.id = d.staff_id) ;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM