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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:15:30+00:00 2026-06-11T08:15:30+00:00

I am trying to create a wall post script like facebook In the newsfeed

  • 0

I am trying to create a wall post script like facebook

In the newsfeed area it should display posts from current user and friends.

I am using three tables:

  1. Users:
    userid, username, fname, lname, sex, email.

  2. posts:
    post_id, username, posted_by, title, type.

  3. friends:
    Id, user1, user2.

When any user adds another user both will be added to the friends table.

I am using mysql view to create a temporary table to store all friends of current user with this statement:

$friends = "CREATE VIEW ".mysql_real_escape_string($_SESSION['username'])." AS 
    SELECT users.username "."FROM users, friends "."
    WHERE ((users.username = friends.user1 OR users.username = friends.user2) AND 
    (users.username != '".mysql_real_escape_string($_SESSION['username'])."')) AND 
    (friends.user1 = '".mysql_real_escape_string($_SESSION['username'])."' OR 
    friends.user2 = '".mysql_real_escape_string($_SESSION['username'])."')";

mysql_query($friends) or die(mysql_error());

I am using below statement to display posts on page:

$query = "SELECT posts.*, user.fname, user.lname, user.username "."FROM 
    posts, users, ".mysql_real_escape_string($_SESSION['username'])." "."
    WHERE 
    (users.username = ".mysql_real_escape_string($_SESSION['username']) ".username 
    AND users.username = posts.username) OR 
    (users.username = '".mysql_real_escape_string($_SESSION['username'])."' AND 
    users.username = posts.username) 
    ORDER BY posts.post_id DESC LIMIT 0, 11";

The problem is, it displays friends posts without any issue; but posts from the current users are repeated, once for each friend.

In other words, if I have 5 friends then each of my posts will be displayed 5 times.

Please let me know what’s wrong with this query and post me if there is any better way to do this.

  • 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-11T08:15:32+00:00Added an answer on June 11, 2026 at 8:15 am

    You need to use the MySQL GROUP BY Aggregate:

    $query = "SELECT posts.*, user.fname, user.lname, user.username "."
        FROM posts, users, ".mysql_real_escape_string($_SESSION['username'])." "."
        WHERE (users.username = ".mysql_real_escape_string($_SESSION['username']) ".username  
        AND users.username = posts.username)
        OR (users.username = '".mysql_real_escape_string($_SESSION['username'])."' AND 
        users.username = posts.username) 
        GROUP BY posts.post_id
        ORDER BY posts.post_id DESC
        LIMIT 0, 11";`
    

    This will group a post into 1 row based on post_id.

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

Sidebar

Related Questions

I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying to create an application that posts specific information on a user's
I'm trying to use the Facebook C# SDK to publish posts to the wall
I have been trying to make wall post from multiple pages but when i
I'm just trying to make PHP Connector to Facebook for posting wall posts on
I'm trying to post to a facebook wall, without using an API such as
I am trying to create an ajax login script but have hit a wall.
Does anyone know if I can create wall posts with html content using facebook's
I'm trying to post on user's wall with embed video. I have created app,
I am trying to create a PHP commenting system similar to facebooks wall but

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.