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

  • Home
  • SEARCH
  • 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 7033125
In Process

The Archive Base Latest Questions

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

I’m building a forum software and am trying to grab all the posts by

  • 0

I’m building a forum software and am trying to grab all the posts by a particular ‘profile’, grab all of the profiles that have ‘liked’ each post (“likers”), followed by a third fetch of the profile data of each profile that has liked each post (profile_name, etc.).

Table 1 - posts
---------------
post_id
profile_id (original poster)
content
...

Table 2 - like
--------------
profile_id
post_id

Table 3 - profiles
------------------
profile_id
profile_name
...

Some rules:

  • Each like is simply a relation of the post_id and profile_id
  • A profile cannot like a post more than once
  • A profile cannot like their own post

I’m stuck on the step where I store all the like profile_ids (“likers”) into an array, if using PHP to fetch the data. Here is what I have so far:

SELECT post.*, COUNT(`like`.profile_id) AS like_count 
  FROM post LEFT OUTER JOIN `like` ON post.post_id = `like`.post_id 
    WHERE post.profile_id = "'.$this->profile_id.'" GROUP BY post.post_id

Thanks in advanced. I’ll try and update this if I find any mistakes, or if any are pointed out to me.

  • 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-28T01:01:27+00:00Added an answer on May 28, 2026 at 1:01 am

    To select all the posts from a particular profile you simply would do the following query:

    SELECT *
    FROM posts
    WHERE profile_id = (the id number)
    

    To grab all the profiles and their data which have liked a given post you would do the following:

    SELECT *
    FROM profiles
    WHERE profile_id IN (
        SELECT profile_id
        FROM like
        WHERE post_id = (the post id number) )
    

    Combining these two queries with IN would allow you to specify a profile and get the profile data for all those who have liked any post on that person’s profile. The query would look like this

    SELECT *
    FROM posts
    WHERE profile_id = (the id number)
    

    To grab all the profiles and their data which have liked a given post you would do the following:

    SELECT *
    FROM profiles
    WHERE profile_id IN (
        SELECT profile_id
        FROM like
        WHERE post_id IN (
            SELECT post_id
            FROM posts
            WHERE profile_id = (the id number) )
    

    If you wanted to grab a list of the post information as well as the profile data for all those who liked each post and the posts themselves, you would use a JOIN as follows…

    SELECT *
    FROM profiles JOIN posts ON (profiles.post_id = posts.post_id)
    WHERE ...
    

    … which would simply aggregate the data from the two tables into one query. You would then pull out the data to treat with PHP as need be.

    If you want to implement rules such as a user cannot like his or her own post, you will have to write that into your php whereby when somebody tries to like a post there is a verification whether or not it is his or her own. You would not want to, for example, allow somebody to like a post, write the like to the database, and then when a page is loaded verify through a query whether or not that person has permission to do so.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to create an if statement in PHP that prevents a single post
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.