2014-03-13 64 views
0

我已經創建了一個學生計劃打印輸出的這個連接聲明,我是新的SQL和PHP,並不能找出我做了什麼不正確。如果有人可以幫助我將不勝感激。在此先感謝...(P.S。我很抱歉,如果這是一個非常基本的問題)......MYSQL聲明無法弄清楚什麼是錯的

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); 
+6

你會得到什麼錯誤?什麼不行?你做了什麼來解決這個問題? –

+0

如果可以,您應該將連接切換到mysqli或使用PDO,而不是棄用的mysql_connect。對不起,在這裏說這是必須的,所以我想我會是這樣做的! – Jack

回答

6

你有一個報價的問題。擺脫在你列的別名和使用引號的蜱

$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)"; 
+0

謝謝完美的作品..... – user3415402

0

您需要使用反勾在查詢,而不是雙引號的字段。選中此項:

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) ;