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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:03:33+00:00 2026-06-18T00:03:33+00:00

In my small application, I have events that can have multiple images associated with

  • 0

In my small application, I have events that can have multiple images associated with them.

For example, the event “snowboarding”, may have three images associated with it.

Here are my tables:

Events
   event_id  title

Event_Images
   event_image_id   image_src   time_uploaded

Here is the query that I am currently using:

SELECT * FROM Events, Event_Images 
   WHERE Events.event_id = Event_Images.event_id 

It results in the following data:

[
    {
        "event_id": "67",
        "title": "Setting up the UGS App!",
        "event_image_id": "64",
        "image_src": "uploads/50f47bce35d4f.jpg",
        "time_uploaded": "2013-01-14 16:42:41"
    },
    {
        "event_id": "67",
        "title": "Setting up the UGS App!",
        "event_image_id": "92",
        "image_src": "uploads/49f4709eppdl.jpg",
        "time_uploaded": "2013-02-14 12:44:43"
    }
]

However, this seems redundant to me. The data structure I imagine would be the least redundant would appear like so:

[
    {
        "event_id": "67",
        "title": "Setting up the UGS App!",
        "event_image_id": "64",
        "images": [
            {
                "image_src": "uploads/50f47bce35d4f.jpg",
                "time_uploaded": "2013-01-14 16:42:41"
            },
            {
                "image_src": "uploads/49f4709eppdl.jpg",
                "time_uploaded": "2013-02-14 12:44:43"
            }
        ]
    }
]

I imagine that either the current way I am doing it is correct, or there is a method that will result in a less redundant result from my query.

Pardon my ignorance if this seems like a simple question.

Any references or help is greatly appreciated.

  • 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-18T00:03:34+00:00Added an answer on June 18, 2026 at 12:03 am

    Ok, thanks to inhan I have my answer– use php to format the data after it is returned. With this information, I just wrote a reuseable function:

    function merge_data($data, $merge_key, $merge_prop, $merge_data) {
        /* build an array of the merge data arranged by the merge key */
        $associated_data_keys = array();
        foreach($data as $value) {
            $grouped_merge_data = array(); // group together the merge data
            foreach($merge_data as $merge_value) {
                $grouped_merge_data[$merge_value] = $value[$merge_value];
            }
            if (empty($associated_data_keys[$value[$merge_key]])) {
                $associated_data_keys[$value[$merge_key]] = array();
            }
            array_push($associated_data_keys[$value[$merge_key]], $grouped_merge_data);
        }
    
        /* remove duplicate data values */
        $existing_keys = array();
        foreach($data as $key => $value) {
            if (!in_array($value[$merge_key], $existing_keys)) {
                array_push($existing_keys, $value[$merge_key]);
            } else {
                unset($data[$key]);
            }
        }
    
        /* remove merge data properties */
        foreach($merge_data as $value) {
            foreach($data as $key => $data_value) {
                unset($data[$key][$value]);
            }
        }
    
        /* put our data from the first statement back into our data set */
        foreach($data as $key => $value) {
            /* assign our data set at this value at the merge property to the corresponding merged data */
            $data[$key][$merge_prop] = $associated_data_keys[$value[$merge_key]];
        }
    
        return $data;
    }
    

    Use in this case:

    $events = merge_data($events, 'event_id', 'images', array('event_image_id', 'image_src', 'time_uploaded'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small application which embeds webbrowser controls. In that application I have
I have a small application that uses WCF to communicate with a webserver. This
I have a small application that I am building a Chat application into, so
I have a small application that uses a SharePoint list as the data source.
I have a small application in java which searches images using bing image search.
I have a small application that redirects the stdout/in of an another app (usually
I have a small application which can be used to set reminders for future
I'm working on a small web application that will let users enter calendar events.
I have written a java application that sporadically logs events to an SQLite database
I'm trying to write a small application and have come across a compile time

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.