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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.