How to JOIN three tables in Codeigniter?

Today, We want to share with you codeigniter join 3 tables.In this post we will show you codeigniter join 2 tables, hear for codeigniter join 4 tables we will give you demo and example for implement.In this post, we will learn about Join Query In Codeigniter Example Tutorial with an example.

how to join two different database tables in codeigniter?

Use this code in model

public function funcname($id)
{
    $this->db->select('*');
    $this->db->from('Album a'); 
    $this->db->join('Level b', 'b.cat_id=a.cat_id', 'left');
    $this->db->join('Soundtrack c', 'c.movie_id=a.movie_id', 'left');
    $this->db->where('c.movie_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;
    }
}

Codeigniter join multiple tables

$this->db->select('*');
$this->db->from('members');
$this->db->join('account_image', 'account_image.member_id = members.id');
$this->db->join('city', 'city.member_id = members.id','left');
$this->db->join('post', 'post.member_id = members.id','left');
$this->db->join('relatives', 'relatives.member_id = members.id','left');
$this->db->where('members.id', $id); 
$query = $this->db->get();

Will produce

// Select *from members
join account_image on account_image.member_id = members.id
left join city on city.member_id = members.id
left join post on post.member_id = members.id
left join relatives on relatives.member_id = members.id
where members.id = $id

I hope you get an idea about codeigniter join three tables.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.