I’m currently making my own social network and I have a php problem which I do not know how to solve.
So my aim is to display the posts made by the user himself and his friends whereas if you weren’t their friends, their posts would be hidden to you.
I have done many research trying to find the answer aswell as implementing the answers but nothing seems to work for my script.
So, here’s what my table looks like:
users: key, id, fullname, username etc…
posts: id, feedusername, author, feedpost
shares(AKA friends): id, userId1, userId2, status
At the moment, I am displaying the posts with a while loop.
while($feedarray = mysql_fetch_array($search)) {
*I pull the users post data here by using that fetch_array function and echo them out*
}
And the $search SQL code is this:
$search = mysql_query("SELECT * FROM posts ORDER BY id DESC LIMIT 0,20");
At the moment, this displays all of the posts regardless if you’re friends or not friends with that user. Which is not what I want.
So, how do I display my own posts and my friends posts? And if your not friends with lets say, “a”, then how do you not display the post’s made by “a” to that user who isn’t friends with “a”?
In other words, if chaotic(userId1) is friends with max(userId2) and their status is equal to 2(if status is equal to 2, then they are friends. If it’s 1, the friend request is pending.)
How do I display my own posts(chaotic’s posts) and Max’s posts? Whereas If this record does not exist or status is equal to 1, I wouldn’t be able to see Max’s posts.
Hope you understand what i’m saying and thank you for your time.
Thanks!
ChaoticS
So from what you’re saying I gather getting your own posts would involve something like:
So, given we now want friends, think of how you retrieve friends. It’s going to be something like:
(And may have to make another query reversing the userid1/userd2 columns, depending how your table is setup). So, given that, it’s a matter of combining the two forms:
You can keep expanding on how you use sub-selects, etc. to be more inclusive/exclusive, but I’ll leave that up to you. If you’re still having trouble leave me a comment and I’ll do my best to help.