SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question HTML in MYSQL database

    Is it ok to put a chunk of HTML code into MySQL database columns? Is it efficient/ slow or bad practice? If it is sensible to do it, what paramaters do I set for the column? TEXT?, VARCHAR? or some other column type?

    The HTML I am thinking of putting in the db will be table rows each with 2 td's. One <td> will have a product description with bullet points and links and the other td will have an image (image path I should say) that will be linked. The thing is, the structure of what will be in each row will be mostly the same, but at times may vary. That's why I am thinking of storing HTML. If it were always a consistent pattern then I probably wouldn't store HTML; I would just store the respective data and let PHP repeatedly write the HTML.
    Last edited by frankdux; May 23, 2004 at 08:26.

  2. #2
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see any problems with it, in fact this forum does it.
    success is not by chance, it is by choice.

  3. #3
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sahajin
    I don't see any problems with it, in fact this forum does it.
    Is there anyone else out there who stores sections of html in a mysql database?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by frankdux
    Is there anyone else out there who stores sections of html in a mysql database?
    yes. millions of us do
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    yes. millions of us do
    Ok. I was just asking because I had the impression that it was better to let php write the html as well as obtaining and inserting the data from the database.

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    in a case like yours, yes, i'd probably script the html, and store just the contents of the TDs in the database

    what's different between various rows that you have to store the html?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    in a case like yours, yes, i'd probably script the html, and store just the contents of the TDs in the database

    what's different between various rows that you have to store the html?
    Sometimes a price and a part number is listed, but sometimes only a price range is given. Also, sometimes product features are listed in bullet points, but sometimes it needs to be in a paragraph. These and a few other minor variations made me think of doing a php function that writes out the tr's and td's but any HTML and data that sit in the td's would be stored in the database.

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    well, for what it's worth, your idea will work

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    The best way would probably be to try to find a way to keep the presentation and the data completely separate.
    I don't think there's anything inherently wrong with storing HTML in a DB, but there may be something inherently wrong with storing your data and HTML all mixed together.
    If you treat HTML as part of your data(because it's really not, HTML is just a way to present it), this could cause trouble down the road.
    But if this not a part of a large complex system, or part of a system that has potential to grow large and complex, you probably don't have to worry as much.
    Just don't paint yourself into a corner.

    --ed

  10. #10
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by coo_t2
    The best way would probably be to try to find a way to keep the presentation and the data completely separate.
    I don't think there's anything inherently wrong with storing HTML in a DB, but there may be something inherently wrong with storing your data and HTML all mixed together.
    If you treat HTML as part of your data(because it's really not, HTML is just a way to present it), this could cause trouble down the road.
    But if this not a part of a large complex system, or part of a system that has potential to grow large and complex, you probably don't have to worry as much.
    Just don't paint yourself into a corner.
    --ed
    Ed, you are touching on exactly what I've been wrestling with. I have been thinking, like you're saying- keep presentation and data separate. The data and HTML would be mixed together, which means some data is going to be duplicated in the database. For example prices and part numbers are already in their own columns. Maybe the solution is to write 2 or 3 different functions, which should cover the possible different presentations.

    An example of the different types of presentations I am talking about can be found at: http://www.microdaq.com/products/temperature.php

  11. #11
    SitePoint Zealot colinr's Avatar
    Join Date
    Aug 2003
    Location
    san francisco, ca
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it depends who will have access to put the html there.. if its just you, its fine.. but if its anyone (public) it's not good
    Web Slave

  12. #12
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by frankdux
    Ed, you are touching on exactly what I've been wrestling with. I have been thinking, like you're saying- keep presentation and data separate. The data and HTML would be mixed together, which means some data is going to be duplicated in the database. For example prices and part numbers are already in their own columns. Maybe the solution is to write 2 or 3 different functions, which should cover the possible different presentations.

    An example of the different types of presentations I am talking about can be found at: http://www.microdaq.com/products/temperature.php
    If you have a table that holds "untainted" data, I wouldn't even worry about, just store the html+data where you want, as long as you don't "taint" the main data.
    Actually, I don't even take my advice. I'm using a little CMS I wrote, and right now I'm entering HTML in along with the articles, which are stored in a text field.
    Eventually(hopefully soon) I'm probably gonna start using an a approach like Kevin Yank describes here:
    http://www.sitepoint.com/article/get-xsl-dirty-work/1 .
    The only downside I see to storing XML is the cost of transforming it. But in most cases you can cache your output with something like jpCache anyway, so..

    --ed


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •