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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:44:25+00:00 2026-05-15T11:44:25+00:00

I need to build an activity feed to go on each users profile page

  • 0

I need to build an activity feed to go on each users profile page showing what they have been doing on the site.

There is three tables: comments, ratings, users

I want the feed to include the comments and ratings that the user has posted.

in the comments and ratings table it stores the user id of the user who posted it, not the username, so in for each item in the news feed it needs to select from the users table where the user id is the same to retrieve the username.

All the entries in the feed should be ordered by date.

Here is what ive got even though i know it is not correct because it is trying to match both with the same row in the users table.

SELECT comments.date, comments.url AS comment_url, comments.user_id, ratings.date, ratings.url AS rating_url, ratings.user_id, users.id, users.username
FROM comments, ratings, users
WHERE comments.user_id=%s
AND comments.user_id=users.id
AND ratings.user_id=%s
AND ratings.user_id=users.id
ORDER BY ratings.date, comments.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-05-15T11:44:26+00:00Added an answer on May 15, 2026 at 11:44 am

    JOIN. It seems you know that, but here’s how:
    SELECT * FROM comments LEFT JOIN users ON comments.user_id = users.id

    Thus, as far as I can tell, you’re trying to order two separate things at the same time. The closest I think I can come up with would be something like:

    (SELECT comments.date AS date, users.username AS name, comments.url AS url CONCAT('Something happened: ',comments.url) AS text 
        FROM comments LEFT JOIN users ON comments.user_id = users.id 
        WHERE users.id = %s)
    UNION
    (SELECT ratings.date AS date, users.username AS name, ratings.url AS url CONCAT('Something happened: ',ratings.url) AS text
        FROM comments LEFT JOIN users ON comments.user_id = users.id 
        WHERE users.id = %s)
    ORDER BY date DESC LIMIT 0,10
    

    Note that the columns of both parts of the union match up. I’m pretty sure that that is required for something like this to work. That’s why I have that CONCAT statement, which lets you build a string that works differently between ratings and comments.

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

Sidebar

Related Questions

I have to build a dynamic form in my activity depending on the data
I have an Android project where I need to build a client app to
I need to build a simple, single user database application for Windows. Main requirements
I need to build a managed DLL, targeted for x64, and expose it via
I need to build something that starts serving a H.264 encoded video to a
We need to build an administration portal website to support our client/server application. Since
I need to build a simple HTTP server in C. Any guidance? Links? Samples?
I need to build a prototype for an intranet website, and I want to
I need to build a little webapp but I'm not sure what is the
I need to build a function which parses the domain from a URL. So,

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.