我想在codeIgniter
中使用Active Record类从4个表中选择数据我的表格 老师(id_teacher,姓名) 学生(id_parent,name,id_teacher,id_class,id_school) class(id_class,libelle) 学校(id_school,姓名)
这是我的代码:
$this->db->select("t.*, s.*, c.*, sh.*");
$this->db->from("teacher t");
$this->db->join("student s","t.id_teacher=s.id_teacher");
$this->db->join("class c","c.id_class=s.id_class");
$this->db->join("school sh","c.id_school=sh.id_school");
$query = $this->db->get();
但它不起作用。你能帮帮我吗?
答案 0 :(得分:0)
您有两个from()
我用join()
public function test() {
$this->db->select("t.*, s.*, c.*, sh.*");
$this->db->from("teacher t");
// $this->db->join("student s","t.id_teacher=s.id_teacher");
$this->db->join('student s', 's.id_teacher = t.id_teacher' , 'LEFT');
$this->db->join('class c', 'c.id_class = s.id_class', 'LEFT');
// $this->db->from("school sh","c.id_school=sh.id_school");
$this->db->join('school sh' ,"sh.id_school = c.id_school", 'LEFT');
$query = $this->db->get();
return $query->result_array();
}
如果需要特定类型的JOIN,可以通过函数的第三个参数指定它。选项包括:左,右,外,内,左外和右外。
//....
<form action="/servlet/UpdateUser" method="POST" accept-charset="utf-8" class="form" role="form">
//....
<button class="btn btn-lg btn-block signup-btn" type="submit" name="signup">Create my account</button>
</form>
//....