Help with db layout
I am geting started on my first real database project, and I have a couple of questions.
I am making a table for articles in a magazine. My question is, concerning the images that accompnay a story, should I use a difernt column for each image, like image1, image2, image3, or can (or should) I put the three images in one column together? (The amount of images will probably vary with each story).
Also, I want to use the primary key from one table in this new table, so all I have to do is use the same column name right?
i am using mysql, if that makes a difference
If you say the amount of images varies it is IMO best to put the images delimited by some character into one column and using PHP / Perl to display them afterwards properly.
thats what i was thinking, but how would i go about that?
Personally, I would create another table that contains the images for an article. I wouldn't put a variable field in a database, but that's just me...
You can make a second table to store the pictures and a id link, for example:
First, in your main table make a id field if you don't already have one. Then make a new table to store your pictures, with each having a id number w/ the exact same id number as the corresponding entry in the main table.
So if you had a user "17", then if they wanted to have a picture you insert it into the picture table with it's link_id number also as "17". And so on. Then to select all the pictures you simply "SELECT * FROM picture WHERE link_id = 17" and you'd get a list of all the pictures.
It's fast & easy. :)
yep it seems like thats the route im gonna go...with a seperate table for the images
read a little bit on database normalization on devshed.com (under mysql)
it will make it much simpler to create a well planned db that way.