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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:17:19+00:00 2026-05-29T08:17:19+00:00

I want to make a page everything on my website where will be all

  • 0

I want to make a page “everything” on my website where will be all my users activity presented. So I need to make sql from two tables “images” and “user_favorites” and output all to this html design

My tables structure:

users

id

images

id
user_id
image
description
date

user_favorites

id
date

I have got this sql query

function users_everything($user_id)
{
    $sql = "SELECT 
                i.description as text, 
                UNIX_TIMESTAMP(i.date) as image_date, 
                COALESCE ( imgcount.cnt, 0 ) as comments,
                fav.id as favorite_id,
                r.image as favorited_image,
                u2.username as favorite_user,
                t.image as favorite_user_image                                                            
            FROM users u
            LEFT JOIN images i ON i.user_id = u.id
            LEFT JOIN images p ON p.id = (SELECT b.id FROM images AS b where u.id = b.user_id ORDER BY b.id DESC LIMIT 1)
            LEFT JOIN (SELECT image_id, COUNT(*) as cnt FROM commentaries GROUP BY image_id  ) imgcount ON i.id = imgcount.image_id

            LEFT JOIN user_favorites fav ON fav.user_id = u.id                
            LEFT JOIN images r ON r.id = fav.image_id
            LEFT JOIN users u2 ON u2.id = r.user_id                                
            LEFT JOIN images t ON t.id = (SELECT b.id FROM images AS b where u2.id = b.user_id ORDER BY b.id DESC LIMIT 1)                                                                

            WHERE i.user_id = ?
            ";

    $query = $this->db->query($sql, $user_id);

    return $query->result_array();
}

My “images” table have 1 record and “user_follow” 2 records but if I do foreach it returns two favorites and two images (image) was duplicated.

I do not make such things like everything page before where will be presented data from different pages to different html structure. I suppose you have experience with it and helps 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-29T08:17:20+00:00Added an answer on May 29, 2026 at 8:17 am

    You need to convert your array of flat records into a tree structure in which each image contains a list of favorites. Something like:

    $images = array();
    foreach($everything_list as $item)
    {
        // Check to see if already encountered this image
        $imageId = $item['image_id'];
        if (!isset($images[$imageId]))
        {
            // New image
            $image = array();
    
            // Do this for each image attribute
            $image['image_id'] = $item['image_id'];
    
            $image['favorites'] = array();
            $images[$imageId] = $image;
        }
        // Add Favorite
        $favorite = array();
    
        // Do this for each favorite attribute
        $favorite['favorite_id'] = $item['favorite_id'];
    
        $images[$imageId]['favorites'][] = $favorite;
    }
    print_r($images);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make my php page only accessible from another page redirect and
I want to make a one page website with a div (navigation) with fixed
I have MOSS. I want to make a page where a user, say administrator,
I want to make a registration page for clients, that would only contain a
I want to make some clicks with Jquery dynamically onLoad of a page. I
I want to make it so the url shows the cat_name of the page
I have created a page on Wiki and I want to make the contents
Hello I have a word press options page and I want to make it
I have a flash object in my page that i want to make as
I want to know whether 301 redirect always preserve referrer. I make a page

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.