Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-11-2002, 10:07 AM   PM User | #1
mat
Regular Coder

 
Join Date: Jul 2002
Posts: 199
Thanks: 0
Thanked 0 Times in 0 Posts
mat is an unknown quantity at this point
Cool Database design

I am doing a little fake project to help me learn php basics. It's supposed to just be a small online sotre selling some product, consists of about 5 different product ranges and each has a dynamically generated product gallery with thumbnails of all the products in that range. You can click one and if so up pops a detail.php window with a bigger version image and detail for that product:



See the "sizes available" bit, i would like that to only show as many rows as there are sizes available for that particular product? but this make the database more complicated doesn't it?

the only way i can see it is if i have a table just for sizes available and that each and every size is it's own row. Here is what i am thinking for the database table layout:

product_collection
collectionID [ INT(2) ]
collectionName [ TINYTEXT ]

products
productID [ INT(2) ]
productName [ TINYTEXT ]
productImage [ TINYTEXT ]
productNumber [ TINYTEXT ]
collection [ INT(2) ]

sizes
sizeID [ INT(2) ]
size [ TINYTEXT ]
product [ INT(2) ]

So that means if there are 4 different sizes available for a particular it will have 4 entires (rows) in the "sizes" table.

what do you think of this?

mat,
mat is offline   Reply With Quote
Old 09-11-2002, 10:26 AM   PM User | #2
Ökii
Regular Coder

 
Join Date: Jun 2002
Location: UK
Posts: 577
Thanks: 0
Thanked 0 Times in 0 Posts
Ökii is an unknown quantity at this point
I would try to serialize/implode all the different sizes to makes one string that can then be added to a 'product parameters' field in the database. Then when the string is returned, you can unserialize it and run a for loop to output all stored data.

$var=array("12foot by 8foot","3inches by 6inches","much smaller");
$var=serialize($var);
$addme = "INSERT INTO.... VALUES('$var')";
--------------------------------------
$getme = "SELECT var FROM.....";
$var = unserialize($var);
for($va=0;$va<count($var);$va++) {
echo $var[$va].'<br>
';
}

Fly-typed code - ergo untested.
__________________
Ökii - formerly pootergeist
teckis - take your time and it'll save you time.
Ökii is offline   Reply With Quote
Old 09-11-2002, 02:01 PM   PM User | #3
ritap
New Coder

 
Join Date: Jun 2002
Location: Ohio
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
ritap is an unknown quantity at this point
Thumbs down

I strongly disagree with Okii's suggestion. This is so against database design principles. You never want to concatentate data together. By doing this you loose the ability to easily query on the individual pieces of information. You could do a complicated like query with the concatenated info but the performance would suffer.

The correct way would be to make a seperate table with the allowed values.

Rita
__________________
Rita P.
ritap is offline   Reply With Quote
Old 09-11-2002, 03:45 PM   PM User | #4
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,225
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
I concur with Rita. I design databases for a living.

Here is a decent little tutorial to give you an introduction into data modelling with relational databases:

http://www.surfermall.com/relational/lesson_1.htm
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 09-12-2002, 11:51 AM   PM User | #5
mat
Regular Coder

 
Join Date: Jul 2002
Posts: 199
Thanks: 0
Thanked 0 Times in 0 Posts
mat is an unknown quantity at this point
so you think my original design was o.k?

i'll take a peep now at this tutorial

mat,
mat is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:56 AM.


Advertisement
Log in to turn off these ads.