homepage Welcome to WebmasterWorld Guest from 54.226.191.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
creating category tables or just use lists?
whatson




msg:4484411
 9:36 pm on Aug 13, 2012 (gmt 0)

Say for example you have a product page, and you wish to have 3 images of the product. You can create a field call images, and have a list of all the sources of the images, e.g. image1.jpg, image2.jpg, image3.jpg. Then you can create an array for your images and run a loop to display them.

Alternatively you can create a new table called images, that can match the product up with the images, e.g.
Product ID Image
1 image1.jpg
1 image2.jpg
1 image3.jpg

Which way is the best? and why?

 

swa66




msg:4484560
 8:50 am on Aug 14, 2012 (gmt 0)

As far as I can tell you're asking if normalizing your database is a good thing ?
Sure it's a good thing, it's the essence of being for relational databases.

So yes: separate tables and relations is by far the superior long term choice.
Messing with creating structure yourself inside a field means the database can't help you anymore in the long run.

Just imagine in both cases what happens when you need a separate caption for each image, store the dimensions of the pictures, track the source where you got the picture, copyright status of each image, ...

You need to see a database as much more than a stupid table that holds data in a persistent manner.

topr8




msg:4484567
 9:20 am on Aug 14, 2012 (gmt 0)

exactly as swa66 says

in my images table i store the height,width,alt, and various other info

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved