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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:41:52+00:00 2026-06-08T20:41:52+00:00

I’m using a relational MySQL database for a website where people can create online

  • 0

I’m using a relational MySQL database for a website where people can create online stories by uploading various media: audio clips, photos, videos, etc. The site will feature a login to a personal space where people can create, view and edit the stories. For this question, let’s say the database has 4 tables: memorybox (with meta info about the story, i.e.: title, date and description), audio, photos and video (the latter three have all the media connected to one story in the memorybox table — individual media files are linked to a story by a column with the memorybox ID).

I’m using PHP to select all the media associated with a story, and the story’s metadata, and exporting to an XML file. From the XML I’ll use jquery to display, first, the stories (some sort of icon, with the story title) and then, when the story icon is clicked, all of the media in a story view.

What I want is to associate all media files with only one story (and its metadata). My problem is that I can’t quite get the XML results I need, and am uncertain if the issue is with the query or with the database structure. I have tried to select all where the IDS match, but that gives me a long list of separate entries for each of the media files. I’ve also tried a LEFT JOIN to associate everything with a memorybox ID, but I still get multiple entries for one ID. I tried GROUP BY but that gave me only one row of media data.

Is there a query that can do this or do I need to rethink my database structure?

Thanks, Cheryl

  • 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-08T20:41:54+00:00Added an answer on June 8, 2026 at 8:41 pm

    judging from your question you haven’t wrapped your head around relational databases yet. Do you realize the difference between procedural code and object oriented programming? Going RealtionalDB is a step similar in magnitude.

    Think datasets, always, even if that set contains of only one record. A table is a dataset, a query result is another, a view is one, a join is one that combines two.

    As for your question:
    I understand a story is composed of one record in the memorybox table and one or more records in any of the media tables.

    For this, your table structure is pretty much ok. I imagine
    table memoryboxes(id int, metadata varchar),
    table fotos(memorybox_id int, thefoto clob),
    table audios(memorybox_id int, theaudio club),
    table videos(memorybox_id int, thevideo clob).

    To get ‘the full story’ you best select from all these tables based on the memorybox_id. That means 4 queries (in one transaction for neatness) after each other. Build the xml from those resultsets.

    As for joins:
    A (left) join should behave exactly as you describe. It combines datasets based on a premise (ids being equal in your case). A left join allows records in the dataset ‘on the left’ to be produced even if there is no matching record in the dataset on ‘the right’. Think about it; this will give you all permutations of your datasets that match your predicate. Exactly what you describe.

    As for group-bys:
    A group by (by id I guess) will ‘roll’ a dataset up and as you will have noticed you were required to have the columns in that group-by query either in the group-by clause or in a so called aggregate function (count, min, max, …), meaning either they participated in the resulting grouping (think composite keys in tables) or their final value would be composed of all the data in the underlying dataset group.

    Long story short: your db structure is fine, use 4 separate queries (in a transaction) to get the data out.

    Next steps:
    Try to read a bit more about joins and group-by later, when you want to write a query that lists the amount of associated media in a story for instance:

    select 
        m.metadata, 
        count(f.id) as fotocount, 
        count(a.id) as audiocount, 
        count(v.id) as videocount 
    from 
        memoryboxes m 
        left join fotos f on f.memorybox_id=m.id
        left join audios a on a.memorybox_id=m.id
        left join videos v on v.memorybox_id=m.id
    group by m.metadata
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.