查询结果错误

时间:2018-03-19 10:09:09

标签: php mysql sql codeigniter codeigniter-3

下面的查询在我的codeigniter项目中使用并且只给我一条记录,但是当我在数据库中调用此查询并给我3条记录时。enter image description here

$query = "SELECT `teacher_subjects`.*, `subjects`.* FROM `teacher_subjects` JOIN `subjects` ON `subjects`.`id` = `teacher_subjects`.`subject_id` WHERE `teacher_subjects`.`session_id` = 11 AND `teacher_subjects`.`class_section_id` = 5"; 

$query = $this->db->query($query);

1 个答案:

答案 0 :(得分:0)

试试这个,

$query_statement = "SELECT `teacher_subjects`.*, `subjects`.* FROM `teacher_subjects` JOIN `subjects` ON `subjects`.`id` = `teacher_subjects`.`subject_id` WHERE `teacher_subjects`.`session_id` = 11 AND `teacher_subjects`.`class_section_id` = 5"; 

$query = $this->db->query($query_statement);
return ($query->num_rows() > 0) ? $query->result() : false;