How are multiple images stitched?

How should I implement the database structure for a catalog with products with multiple images?

  • I would like to develope a catalog with products.For each product I would like to add multiple images.I'm not sure how is better to do this.Should I build a gallery table and assign each entry with a product id ? thank you !

  • Answer:

    It depends on the complexity of your structures and how dynamic your content is going to be I suppose. One simple method would be to store the URLs of your images in a text field in a json (or similar) array. This brings potential issues but is worth at least considering to see if it works in your situation. The more foolproof, futureproof and extendable method would be a ProductImages table with URL & ProductID fields as you suggest. This also lets you store extra information such as a thumbnail URL (created in a post-save process?) and image ordering data. The json array method is worth considering (and determining 'why not' in your situation), but as a programming exercise the relational approach is much more worthwhile. Ps you could extend this concept further by exploring a many-to-many relationship if the images can appear in more than one product.

David Lowry at Quora Visit the source

Was this solution helpful to you?

Other answers

As David points out, this comes down to how much extensibility you need and the exact relationships. I'd be tempted to use a many-many model just in case, even if I'm not sure it's needed later on, but that's just me! e.g. Products -  id ; name ; etc.. Images -     id ; title ; dimensions ; fileLocation ; etc. ImagesProducts -   id ; product_id ; image_id ; dimensions ; is_featured Note that the join table might want additional fields, e.g.  if you're using multiple thumbnail sizes, this would allow you to use different sized thumbnails of the same image for different products, and enable a "featured-image" function as well. I have in mind some typical media file systems e.g. Wordpress media, and CakePHP Media plugin which work with these kind of approach.

Adam Marshall

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.