How to JOIN three tables in Codeigniter

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

    Try this one for data...

    function get_album_data() {
        $this->db->select ( 'album.*,cat.*,s_track.*' )
            ->from ( 'albums as album' );
            ->join ( 'categories cat', 'cat.cat_id = album.cat_id')
            ->join ( 'soundtracks s_tracks ', 's_tracks.album_id = album.album_id');
        $query = $this->db->get ();
        return $query->result ();
    }
    

    while for datum try this...

    function get_album_datum($album_id) {
        $this->db->select ( 'album.*,cat.*,s_track.*' )
            ->from ( 'albums as album' );
            ->join ( 'categories cat', 'cat.cat_id = album.cat_id')
            ->join ( 'soundtracks s_tracks ', 's_tracks.album_id = album.album_id');
        $this->db->where ( 'album.album_id', $album_id);
        $query = $this->db->get ();
        return $query->row();
    }7
    

    855788

提交回复
热议问题