我是一个新的MySQL和PHP编码器...大约7年前曾经使用它,但现在它再次落在了我的膝盖上。目前,该代码可以吸引学生进行出勤跟踪,其工作原理如下:
$count = sqlValue("SELECT count(*) FROM `attendance` LEFT JOIN `enrollments` ON attendance.`student_class` = enrollments.id Where enrollments.class='".$class."' AND attendance.date='".$date."'");
if ($count == 0)
{
$query = "SELECT CONCAT_WS('', `students`.`fname`, ' ', `students`.`lname`) as `student`, `classes`.`class_name` as class, enrollments.id as eid FROM `students` LEFT JOIN `enrollments` ON students.id = enrollments.student LEFT JOIN `classes` ON classes.id = enrollments.class";
$query.= " WHERE enrollments.class='".$class."'";
$query.= " ORDER BY students.id";
$res = sql($query, $eo);
$tbody = '';$ids=array();
if(db_num_rows($res) > 0)
这很有效,但现在他们只想展示那些活跃的"。我在数据库中添加了一列,并对前端进行了编码,将学生标记为活动状态。所有这一切都有效,现在我想运行一个只显示活跃学生的查询,然后让我使用复选框将它们标记为该类的存在。我尝试了以下方法,但它不起作用:
$count = sqlValue("SELECT count(*) FROM `attendance` LEFT JOIN `enrollments` ON attendance.`student_class` = enrollments.id Where enrollments.class='".$class."' AND attendance.date='".$date."'");
if ($count == 0)
{
$query = "SELECT CONCAT_WS('', `students`.`fname`, ' ', `students`.`lname`) as `student`, `classes`.`class_name` as class, enrollments.id as eid FROM `students` LEFT JOIN `enrollments` ON students.id = enrollments.student LEFT JOIN `classes` ON classes.id = enrollments.class";
$query.= " WHERE enrollments.class='".$class."'" and enrollments.status <> 'Active';
$query.= " ORDER BY students.id";
$res = sql($query, $eo);
$tbody = '';$ids=array();
if(db_num_rows($res) > 0)
它在第45行引发错误,即$query.= " WHERE enrollments.class='".$class."'" and enrollments.status <> 'Active';
行。
结构是
Table structure for table `enrollments`
--
CREATE TABLE IF NOT EXISTS `enrollments` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`student` int(10) unsigned DEFAULT NULL,
`class` int(10) unsigned DEFAULT NULL,
`enrollment_date` date NOT NULL,
`status` varchar(40) NOT NULL,
PRIMARY KEY (`id`),
KEY `student` (`student`),
KEY `class` (`class`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=109 ;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
答案 0 :(得分:0)
"'"
中还有一个引号。
该行应为:
$query.= " WHERE enrollments.class='".$class."' and enrollments.status <> 'Active'";