I started a new project with CodeIgniter and I create three tables for users and posts and likes like this
user table has these records
- User_ID
- FullName
- UserName
post table has these records
- Post_ID
- Title
- User_ID
that user_id field save creator user_id
and like table
- Like_ID
- User_ID
- Post_ID
I want to join this three tables and I can do it but I need join two result like this and I don't know what can I do
$this->db->select('*');
$this->db->from('Post');
$this->db->join('User', 'User.User_ID = Post.User_ID', 'left');
$query = $this->db->get();
return $query->result();
and this
$this->db->select('*');
$this->db->from('Like');
$this->db->where('User_ID' = $id);
$query = $this->db->get();
return $query->result();
and then join these results with together.
post,user, andliketables and then merely count the number of related records in theliketable? See also: CodeIgniter query builder to JOIN, GROUP BY, and COUNT() rows from one table and codeigniter join count another table and Codeigniter count associated records between 2 tables