How to JOIN three tables in Codeigniter

后端 未结 6 2289
离开以前
离开以前 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:33

    Use this code in model

    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(); 
        if($query->num_rows() != 0)
        {
            return $query->result_array();
        }
        else
        {
            return false;
        }
    }
    

提交回复
热议问题