How to JOIN three tables in Codeigniter
try this
In your model
If u want get all album data use
function get_all_album_data() {
$this->db->select ( '*' );
$this->db->from ( 'Album' );
$this->db->join ( 'Category', 'Category.cat_id = Album.cat_id' , 'left' );
$this->db->join ( 'Soundtrack', 'Soundtrack.album_id = Album.album_id' , 'left' );
$query = $this->db->get ();
return $query->result ();
}
if u want to get specific album data use
function get_album_data($album_id) {
$this->db->select ( '*' );
$this->db->from ( 'Album' );
$this->db->join ( 'Category', 'Category.cat_id = Album.cat_id' , 'left' );
$this->db->join ( 'Soundtrack', 'Soundtrack.album_id = Album.album_id' , 'left' );
$this->db->where ( 'Album.album_id', $album_id);
$query = $this->db->get ();
return $query->result ();
}
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;
}
}