user3111896
user3111896

Reputation: 39

article with unknown amount of images functionality and database structure

I should begin by adding that i'm not very familiar with SQL and database structures, i know the basics but don't think that's more than that. I am trying to build a functionality which is supposed to add an article with unknown amount of images. Each article will consist of 4 parts: title, image or multiple images, description and price. The confusing part here is that one article may have more than 1 image, as so far i've only known how to upload single image at a time.

How do i upload multiple images into database at a time?

As for the database i was thinking of going for the following structure: 2 tables, 1st - 'articles' and 2nd - 'images'. the idea was to first upload the image into 'images' with random 16 character hash name and then post in 'articles' all article fields with a hash reference on the end of the row.

Is this a valid solution or are there any other, more efficient ways?

Upvotes: 0

Views: 46

Answers (1)

teaclipper
teaclipper

Reputation: 48

You will want to place a reference to the article that the images belong to in the images table. Ensure they are the same data type. The article_id will need to be unique (primary key)

When it comes time to retrieve the data in your app you can simply pull the images out that correspond to that article.

Article
--------------------
article_id
article_title
article_descr
article_price

Image
--------------------
image_id
image_article (foreign key links to article_id)
image_path
...

You can get creative and use a image_seq_no to indicate what sequence the image would appear in the article or some reference to paragraph or location.

Upvotes: 1

Related Questions