Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:35:11+00:00 2026-06-14T19:35:11+00:00

I have these tables; user – contains user_id | username | fullname | email

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:35:12+00:00Added an answer on June 14, 2026 at 7:35 pm

    ->where() supports passing any string to it and it will use it in the query, provided you pass a second and third parameter of NULL and FALSE respectively. This tells CI not to escape the query.
    E.g.

    $where_query = "p.user_id = $user_id OR p.user_id IN (SELECT user_id FROM user_followers WHERE follower_id = $user_id)";
    ->where($where_query,NULL,FALSE);
    

    Alternatively, you could check out this subquery library https://github.com/EllisLab/CodeIgniter/wiki/Subqueries

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these tables: USERS: user_ID username password email data_registered POSTS: post_ID user_ID post_title
I have these 3 tables: users table(PK user_id) Fields: user_id, user_first_name, user_last_name, username, user_email...etc
I have these tables: CREATE TABLE User( Username varchar(15) NOT NULL, Name varchar(20) DEFAULT
I have these tables User User_Id int PK, User_Name varchar(50) Page Page_Id int PK,
I have these two tables: 1. users -id -name -email -rank 2. pages -user
I have these three (simplified) tables for a contest application: **user** user_id **contest** contest_id
I have these tables: table_a user_id article_id created_at articles user_id created_at ... I need
I have these tables: comments uid id pid pages pid user users id rank
I have these tables and relationships: user has_many projects project has_many tasks task has_many
I have these tables. tables #__qa_question qid, user_id, date_add, date_modify, question, publish #__qa_answer aid,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.