Codeigniter join multiple tables
$this->db->join(); is used to join tables in codeigniter.
Codeigniter join Multiple tables
$this->db->select('*'); $this->db->from('users'); $this->db->join('profile_image', 'profile_image.user_id = users.id'); $this->db->join('city', 'city.user_id = users.id','left'); $this->db->join('post', 'post.user_id = users.id','left'); $this->db->join('friends', 'friends.user_id = users.id','left'); $this->db->where('users.id', $id); $query = $this->db->get();
Will produce
// Select *from users
join profile_image on profile_image.user_id = users.id
left join city on city.user_id = users.id
left join post on post.user_id = users.id
left join friends on friends.user_id = users.id
where users.id = $id
Advertisements