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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:32:31+00:00 2026-06-10T18:32:31+00:00

I’m having trouble getting some data…. I was wondering if someone can help me,

  • 0

I’m having trouble getting some data…. I was wondering if someone can help me,

I have 4 tables (likes, follow, comment, users)

I want to be able to populate my page when a user likes/comments/follows/etc… (if a user is following a particular user).

likes

idlikes   idusers    iditem
  1          1          5
  2          2          4
  3          2          22

follow

idfollow   idusers_follower   idusers    idbusiness
  1              1               2           
  2              1               3           
  3              1               4           
  4              4               2           
  5              4                           1

comment

idcomments   idusers    text
   1            1       asfd
   2            2       safd

users

idusers
   1
   2
   3
   4

For example if I am id user #1, I’m following users #2, #3, #4

My page would populate to show:

  • #2 likes item #4, #22.
  • #4 is following #2 (because I’m following #4, this is why its showing)
  • #2 comments “safd”

I’m not sure what is the best way to display this? I currently have multiple functions querying on table at a time, and I’m working on merging the arrays together? Or should I use join tables? Which I’m trying now…

Get users that I’m following.

$feeds = new feed();
$meID = 1;
$query = "SELECT idusers FROM follow WHERE iduserse_follower = ?";

$users = $dbh -> prepare($query);
$users -> execute(array($meID));

while($following = $users -> fetch(PDO::FETCH_ASSOC)){
      $follow = $following['idusers']; //This will get all of useres I'm following
      $populate = $feeds->feed_all($follow); // from function
}

Query

class feed()
{
     public function feed_all($idusers)
     {
         // SYNTAX HELP //////////////////////
           $query = "SELECT 
           f.idusers_follower, 
           f.idusers, 
           l.iditem, 
           c.text 
           FROM follow f, users u 
           JOIN likes l 
           ON l.idusers = f.idusers 
           JOIN comment c
           ON c.idusers = f.idusers
           WHERE f.idusers_follower = ? AND f.idusers_follower = l.idusers AND f.idusers_follower = c.idusers AND f.idusers = u.idusers"

           $pop = $dbh->prepare($query);
           $pop ->execute($idusers);

           // while loop to return value
    while($row = $pop -> fetch(PDO::FETCH_ASSOC))
    {
        $feed_data[]=$row;
    }
    return $feed_data;
     }
}

This is where I’m stuck. 🙁 I’m not even sure if I’m doing the statement right?

++++++++++ EDIT: ++++++++++++

I have edited to add idbusiness

Now since I’m following #4, it would also show up that #4 is following #1.

  • 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-10T18:32:32+00:00Added an answer on June 10, 2026 at 6:32 pm

    Your current approach of performing three separate queries is as good as any; you can combine them into a single resultset using UNION, which would be useful if you wanted to sort the combined results by some field (e.g. activity timestamp) and/or limit the combined results:

      SELECT idusers, 'likes' AS what, likes.iditem AS detail
      FROM   likes JOIN follow USING (idusers)
      WHERE  follow.idusers_follower = 1
    
    UNION ALL
    
      SELECT f1.idusers, 'follows', f2.idusers
      FROM   follow f1 JOIN follow f2 ON f1.idusers = f2.idusers_follower
      WHERE  f1.idusers_follower = 1
    
    UNION ALL
    
      SELECT idusers, 'commented', comment.text
      FROM   comment JOIN follow USING (idusers)
      WHERE  follow.idusers_follower = 1
    

    See it on sqlfiddle.

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

Sidebar

Related Questions

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 have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.