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.

Read Also:  How to Open URL in New Tab using PHP

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Get custom product attributes in Woocommerce
  2. Read Also:  How to Remove all special characters from a string in php?
  3. Read Also:  Laravel All Where eloquent methods with Examples
  4. Read Also:  Wordpress Next Previous Article/post using CSS
  5. Read Also:  How to get last inserted id in Laravel
  6. Read Also:  PHP wordpress get timezone Example - MySQL
  7. Read Also:  Laravel 5.7 Route Group Names Example
  8. Read Also:  insert and display data from database in codeigniter
  9. Read Also:  PHP file_get_contents() function Example
  10. Read Also:  Laravel All Where eloquent methods with Examples
CLOSEX