1

I have a article pages, that i only want to show feed of the users that every account is following, kinda like twitter. I have to distinct tables one is called posts other is called followers I want to loop the articles but i want it to select only the users that my account is following. I just need the SQL query that can do that since the PHP part of the rest i can perform it

Something like this , although i know that this one does not work

$connect->query("SELECT id,userid,postagem FROM posts WHERE IN (SELECT followed FROM followers WHERE whofollowed = '$userd' )  ORDER BY id DESC LIMIT 13");

1 Answer 1

1

Assuming followed is also a userid in the followers table:

$connect->query("SELECT id,userid,postagem FROM posts WHERE userid IN (SELECT followed FROM followers WHERE whofollowed = '$userd' )  ORDER BY id DESC LIMIT 13")
Sign up to request clarification or add additional context in comments.

3 Comments

the userid must match in both
the query is saying "select all the posts of followed userids who are followed by the provided userid". You only need to match the provided userid against the followers table to get the userids which that user is following.
Its not looping, i need it to loop all posts that in followed the whofollowed have my username

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.