php - MYSQL语句搞不明白是怎么回事

标签 php mysql sql join syntax-error

我为学生日程表打印输出创建了这个连接语句,我是 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)";

关于php - MYSQL语句搞不明白是怎么回事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22379331/

相关文章:

javascript - 如何添加复选框的值以获得总价

sql - 动态 View 管理查询

sql - 根据规则更新列值

php - $_FILES 表单提交后为空

php - 前0个月的参数导致错误的输出

php - 使用时间戳显示活跃用户?

SQL:按计数 (*) 分组作为总表行数的百分比

Mysql使用存储过程从当前数据库中选择所有现有表

mysql - 如何登录 MySQL 并从命令行执行选择

mysql - mysql 中的存储过程返回 null