How to JOIN three tables in Codeigniter

后端 未结 6 2286
离开以前
离开以前 2020-12-03 13:55

I\'m using codeigniter framework to develop one music cms. i have 3 tables in mysql database, Currently im working in \"Album\" Table and \"Model, Controller\". i want to SE

6条回答
  •  佛祖请我去吃肉
    2020-12-03 14:29

    Try as follows:

    public function funcname($id)
    {
        $this->db->select('*');
        $this->db->from('Album a'); 
        $this->db->join('Category b', 'b.cat_id=a.cat_id', 'left');
        $this->db->join('Soundtrack c', 'c.album_id=a.album_id', 'left');
        $this->db->where('c.album_id',$id);
        $this->db->order_by('c.track_title','asc');         
        $query = $this->db->get(); 
        return $query->result_array();
    }
    

    If no result found CI returns false otherwise true

提交回复
热议问题