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 6649303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:45:28+00:00 2026-05-26T00:45:28+00:00

I’m currently making my own social network and I have a php problem which

  • 0

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

  • 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-05-26T00:45:28+00:00Added an answer on May 26, 2026 at 12:45 am

    So from what you’re saying I gather getting your own posts would involve something like:

    SELECT   *
    FROM     posts
    WHERE    author = @MyUserId
    

    So, given we now want friends, think of how you retrieve friends. It’s going to be something like:

    SELECT   userid2
    FROM     shares
    WHERE    userid1 = @MyUserId
      AND    status = 2
    

    (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:

    SELECT     *
    FROM       posts
    WHERE      author = @MyUserID
      OR       author IN (
        SELECT userid2
        FROM   shares
        WHERE  userid1 = @MyUserId
          AND  status = 2
      )
    

    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.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I want use html5's new tag to play a wav file (currently only supported

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.