0

If I want to store HTML code to a database, is better to add one row with big HTML code or more rows with smaller HTML code?

In my app, I can edit the code in both ways, so don't really need more rows, but maybe is faster or more effective having more rows and smaller HTMl code.

What is your opinion? Thanks you.

HTML Code Example:

<div class="row">
  <div class="col-sm-12">
    <section data-type="component-text">
      content
    </section>
  </div>
</div>
<div class="row">
  <div class="col-sm-6">
    <section data-type="component-photo">
      content
    </section>
  </div>
  <div class="col-sm-6">
  <section data-type="component-video">
    content
  </section>
  </div>
</div>

The code is generated by a plugin. This is only an example created by me.

8
  • Can you elaborate how you would be separating the rows? Commented Mar 28, 2018 at 18:46
  • Why you do not save your html code as file ?,i guess is better than more rows and text. Commented Mar 28, 2018 at 18:47
  • @JakubJudas I edited the post. I would add row by row. Commented Mar 28, 2018 at 18:56
  • @MenaiAlaEddine I need to store logo,nav,footer, and body. I dont't really want to use files. I wante to use Sessions, because is only a temporary store. Commented Mar 28, 2018 at 18:57
  • I'd say that in this case, it will be more future proof to save each content in a separate place than to save the whole thing as html. This will make the content immune to any design changes etc. As for whether to store it as one row with content_video, content_photo and content_text, or another table with content_type and content - I'd say the latter is more future proof too. Commented Mar 28, 2018 at 19:03

1 Answer 1

2

Answer: It depends on your querying needs.

Efficient querying is an extensive topic focused on design and algorithms. It depends on the size, type and structure of the data you have.

If you just need to store all the HTML and get it back, you could simply store as much per block.

If you need specific lines of HTML per query then each block with the necessary content is a good idea!

I hope this helps.

Sign up to request clarification or add additional context in comments.

9 Comments

I edited the with a plugin, so I can store all the HTML and then get it back. The HTML code is stored temporary. Because user can click to another page and I dont want to lose the content.
I see that the content you need is only : text, photo,video. You can store that information only for the specific user say (use different columns) with SQL? Are you using a framework? It makes it easier to just inject the information in the HTML that is there. It would be a lot of wasted table space to store the entire HTML to describe the div's.
There are more components like youtube,googlemaps, but the code is more or less the same.
You don't want to store all the html, it is a little inefficient. I would store only the required information. Depending on the database you are using. If in this case SQL , you can create columns for the necessary types of content.. (can become a lot). If it was a JSON format database, MongoDB it would be pretty good, you could store all fields in a javascript type object. It seems efficient for your type of data. Check it out !
I am making a website builder and user can click to another page, so I want to save temporary the changes he made until he publish the content using Publish button. I've got 3 choices: making a temporary file, session, or database. I must save the HTML inside the section with content-type.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.