I have these tables;
user - contains user_id | username | fullname | email etcc
user_followers - contains follow_id| user_id | follower_id | date etcc
posts - contains post_id | user_id | post | post_date
I’m trying to grab all the posts by the users the user is following and the user’s own posts.
I’ve tried
$this->db->select('posts.*')->from('posts')
->join('user_followers', 'user_followers.user_id = posts.user_id', 'INNER')
->where('user_followers.follower_id', $user_id)->order_by('posts.post_date','desc');
$query = $this->db->get();
But the problem is, i’m not able to get the user’s posts from this query. I’ve tried other methods with or_where etc and i was able to get the user’s posts, only that the data was tripled :( Can someone please help me out here? Many Thanks in advance.
Oh in normal Mysql, its;
SELECT posts.*
FROM posts
JOIN user_followers
ON user_followers.user_id = posts.user_id
WHERE user_followers.follower_id = $user_id
ORDER BY
posts.post_date DESC