开发者

Should I separate this into one field or multiple fields in mysql?

I want to store a bunch of thumbnails with links on a page on my site and so I'm learn开发者_运维问答ing mysql. Here is what a typical thumbnail looks like:

<a href=/otherstuff/nature><img src="https://s3.amazonaws.com/imagefolder/butt      
erflies.png" height="200" width="200" /></a><br /><div id="submit 
ted">description</div>

Pretty simple stuff. But, I wonder, should I just save that as one field, or multiple fields, such that field 1 would have a default value of " <a href=/ ", field 2 would have varying names depending on the file location, field 3 would have the default value of <img src=" https://s3.amazonaws.com/imagefolder/. Field 4 would have... you get the point.

Would chopping up the parts of my code make my database run faster/take less space?

Thanks!


Your looking at this the wrong way...

To go for a simplistic description your database should store the image URLs, links and description text (not outer markup) and your html layer does the rest. For example you would have a simple table that looks something like this:

link                        url                             description
/somelink/somewhere1        https://site.com/lions.png      A lion doing lion things
/somelink/somewhere2        https://site.com/tigers.png     A tiger pretending to be a lion
/somelink/somewhere3        https://site.com/bears.png      Grrrrr bear
/somelink/somewhere4        https://site.com/oh_my.png      Wizard of Oz

You would then query out the values from the table and use that data to construct your html.

This is a massive subject but the sort of thing you are needing is well within the realms of database for beginners. I would suggest that you have a look around for entry level DB tutorials there are many to choose from.

You don't say what you are using to build your pages, but it is worth mentioning that you cannot query a DB from HTML you need to be using something like PHP. The PHP script (that runs on the server) queries the DB, constructs the HTML and returns this to the user.


you don't have a link to your typical thumbnail so I can't be that much help, but in general a rule of MySQL is to never repeat data, but rather to link between tables through primary keys.

You can read about database normalization here: http://en.wikipedia.org/wiki/Database_normalization

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜