Click to See Complete Forum and Search --> : Database structure


Christophe27
01-10-2010, 10:10 AM
Hi,

For the moment I'm learning PHP and MySQL and I have a MySQL question.

I'm creating a website where people simply can registrate and upload images. Now I wonder how I should design my database. I already have a 'user' table with columns like id, name, email, etc.

Do I need another table named 'images' where I can store the names and captions of the images (probably yes), but how can I assign the images from a certain user to the particular user? And how and where to store the images on the server?

Thank you! :)

Best,
Christophe

NogDog
01-10-2010, 06:51 PM
Assuming a given image belongs to one and only one user, you can have a column in the image table which contains the primary key in from the user table for the owning user.

As to where to store the actual image files: wherever you want. :) As long as you assign each upload a unique file name, you can dump them all in the same directory, then you only need to store the file name (and any other descriptive fields) in the image table in the DB.

PS: It might be worth your while to read: http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html

Christophe27
01-11-2010, 07:14 AM
Thank you for the reply and the article! I'll read it this afternoon!

The idea is to create an image table with the following columns:

ID image_name caption user_id

This way I let users upload images and store the name in the 'images' table and immediately assign the user_id to the particular image. When somebody checks their images, PHP checks their ID and ask all images where user_id is 'user id of the particular user'.

Good idea?

Yesterday I have found a tutorial in my book 'PHP Solutions' (great book btw) in how to upload images (yes, I'm a rookie) He create a folder for each individual user. I think I'll do it that way ...

Thank you for your kind reply!

Christophe