这是我的课程表:
student_id || course_id ||组
12345 || 1 || 0
12346 || 2 || 0
12347 || 2 || 1
//for example $course_id = 2 and $group = 0
$query=$this->db->query("DELETE FROM courses WHERE group=".$group." AND course_id = ".$course_id);
$query=$this->db->query("DELETE FROM courses WHERE course_id = ".$course_id);
$query=$this->db->query("DELETE FROM courses WHERE group=".$group);
答案 0 :(得分:1)
group
在mysql中为reserved keyword,用于反引号
$query=$this->db->query("DELETE FROM courses WHERE `group`=".$group." AND course_id = ".$course_id);
或使用Active记录,您可以编写查询
$this->db->where('`group`',$group);
$this->db->where('course_id',$course_id);
$this->db->delete('courses');