Registering multiple images in a post

2

I have 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. On the 1st I would create about 22 columns in a table called postagens , it would be something like ID TITULO IMG1 IMG2 IMG3 IMG4 and so on. I just do not think it's the best shape, because it's so many columns, and not all of them will be filled. On one hand I would be able to work with each image individually.

In the 2nd hypothesis I thought of only 3 columns, something like ID TITULO CONTEÚDO . This Conteúdo would be the HTML code of the entire post, but in this case I'm limited, as it will not work with each image individually.

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

    
asked by anonymous 16.11.2014 / 22:20

1 answer

3

One option is to type what WordPress does, in a table if it stores the data of the post and in another the metadata of each one. In fact, WP treats the image as a post and associates it with a specific post using the post_parent column.

A simplified option:

  • POSTS table

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

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

Or one more like WordPress:

  • POSTS table

    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)      
    
17.11.2014 / 13:34