Jump to content

Storing Product Information - ADVICE NEEDED


Canman2005

Recommended Posts

Hi all

 

I need some advice, basically im building a shopping cart and I have this example as one my product lists

 

main category (cloths)

sub category (tshirts)

sub sub category (funny tshirts)

sub sub sub category (starwars)

sub sub sub sub category (R2D2)

 

I need to store what categories each product is assigned to.

 

Now I need some advice, should I have in my products table the following fields

 

maincat

subcat

subsubcat

subsubsubcat

subsubsubsubcat

 

and store the relevant category ID numbers in each field of those 5 fields?

 

Or should I just have one field and store the category ID numbers in one field, for example 2,34,234,543,788

 

Does that make sense?

 

Thanks

 

Ed

try

[pre]

table category

---------------

catID    (PK)

category

parentID

 

data

+-------+----------------------+----------+

| catID | category            | parentID |

+-------+----------------------+----------+

|  1  | cloths              |    0    |

|  2  | tshirts              |    1    |

|  3  | funny tshirts        |    2    |

|  4  | starwars            |    3    |

|  5  | R2D2                |    4    |

|  6  | shirts              |    1    |

|  7  | long-sleeve          |    6    |

|  8  | short-sleeve        |    6    |

+-------+----------------------+----------+

[/pre]

You only need the association table if a product can belong to more to one category.

 

If a product belongs to only one category

 

 

[pre]

category              product

----------            -------------

catID    -----+      productID

category      |      prod_description

parentID      +---<  catID

[/pre]

 

If a product can belong to more than one category

 

[pre]

category              prod_category        product

----------            -------------        ----------

catID    -----+      id              +---- productID

category      |      productID  >---+    prod_description

parentID      +---<  catID

[/pre]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.