Registering multiple images in one post

Asked

Viewed 133 times

2

I’m with a study project that has to create a kind of gallery. Assuming I have a limit of 20 images per post. How to register these images in the database?

I thought of two hypotheses. In the first I would create about 22 columns in a table called postagens, would be something like ID TITULO IMG1 IMG2 IMG3 IMG4 and so on. I just don’t think it’s the best way, because it’s so many columns, and not all of them will always be filled. On the one hand I was going to be able to work with each image individually.

In the second hypothesis I thought of only 3 columns, something like ID TITULO CONTEÚDO. That one Conteúdo would be the HTML code of the entire post, only in this hypothesis I am limited, because I can not work with each image individually.

I am in doubt between these two hypotheses. Is there a 3rd 4th or 5th? Remembering that the project works directly with images, so the malleability in relation to the administration of the photos is a crucial point

  • 1

    What’s the problem with multiple columns and empty fields? Having to keep unlocking HTML to pull information doesn’t make much sense...

  • On second thought, I think you already know what’s best between option 1 and 2. And what you’re looking for is option 3, 4 or 5, but then I think you’d better present a basic DB design and what problems you have with it. . . . Did you ever check the site files? http://answall.com/search?q=%5Bmysql%5D+images+is%3Aquestion

  • Vlw @brasofilo. I really preferred the 1st option, only I found this hypothesis a little unfeasible, because I thought it could be too many useless spaces.

  • @Brasofilo, I found a third alternative. Whenever you upload the images, the code will create a unique folder name, and in the BD it will type the ID || Title || Folder name || Cover Image. Then when I click on the post, php will take the name of the folder referring to that post and will list everything. I function EXACTLY as I wanted. And very simple.

  • @Brasofilo what you say is also a good, and it’s something simple too right. I hadn’t thought about it. And look who I’ve done it in, it was only in a comment system.

1 answer

3


One option is to type Wordpress does, in a table store the data of post and in another the meta-data of each. In fact, WP treats the image as if it were a post and associates it with another post specific using the column post_parent.

A simplified option:

  • table POSTS

    ID          TITLE           CONTENT
    id-post     titulo-post     conteúdo-post
    
  • table IMAGES

    ID          POST_ID         URL
    id-imagem   id-post         info-imagem
    

Or one more similar to Wordpress:

  • table POSTS

    ID          TITLE           CONTENT         TYPE            PARENT
    id-post     titulo-post     conteúdo-post   tipo-de-post    idPost-ou-zero
    
  • meta table

    ID          POST_ID         META_TYPE       META_VALUE
    id-meta     id-post         tipo-de-meta    valor-do-meta(url,exif,etc)      
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.