PDA

View Full Version : I need advice on “proper database storing”. A clean database is a happy database :)


TylorFamous
03-24-2008, 05:02 PM
Hello,

I am very new to MYSQL and Php working with flash and I just had a some questions about databases and stuff. I have made some stuff where php and flash can “talk” to each other to get information from a MYSQL database. But I am working on a project that includes dressing up a character (and the clothing choices are going to be saved into a mysql database). Right now I would have a table named Clothing and then have fields named Hat and Shirt and so on. Once people started to save their clothing into the database it would start to look like this:

Hat: Pink Flower Hat
Shirt: Red shirt
Pants: Blue Jeans

...And so on. This would work fine for me but I end up with a ton of fields, all related to the clothes.
My Question is this:

Can I just store all of the clothing information into ONE field? And have it look something like:
Clothing:
Hat=pink_flower_hat&shirt=Red_shirt&pants=blue_jeans

Or however I would store them. Would it be considered bad practice to store all of the clothing information into one field? Or should I just end up with a thousand little fields? I am just asking because I don't know how I should set it up. I imagine with sites like Webkinz where you would have an inventory you would store all the information in ONE field? Maybe I am wrong but I would love to know either way. Thanks for any help!

Thanks for any advice on “proper database storing”

ASWC
03-24-2008, 05:52 PM
Yes you can do that and yes it's bad practice! For your project it would make sense to store each available items (clothing) into one table and give them an ID (primary key) maybe integer or long depending on how big is your application. Then a second table where you keep record for each user (you might have a user table too):
user->ID
Hat->ID
shirt-> ID
And so on that way the database will run faster too since they don't like text that much. When your Flash calls the PHP, the PHP check the user, his/her settings, then use the IDs to look in the clothing table and retreive the right items.

yell0wdart
03-24-2008, 06:41 PM
Yea, definitely bad practice. I'd suggest googling around a little bit to find some decent tutorials or books on database design. ASWC has some good ideas. I'd do a table for users, and a table for clothing. If you have a LOT of different clothing items, then maybe a table for each category (pants, shirts, hats, etc).

ASWC's comments on ID's is VERY important. Each record in a table should have its own unique ID. Identity columns should NEVER be used or made available for use by the end user.

You'd then be setting up relationships between users and clothing.

If you want to do it right, I'd highly suggest reading up on good relational database design practice, table relationships. You'll probably want to read up on doing table joins (inner and outer) in MySQL.