Canman2005 Posted July 12, 2008 Share Posted July 12, 2008 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 https://forums.phpfreaks.com/topic/114428-storing-product-information-advice-needed/ Share on other sites More sharing options...
Barand Posted July 12, 2008 Share Posted July 12, 2008 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 https://forums.phpfreaks.com/topic/114428-storing-product-information-advice-needed/#findComment-588496 Share on other sites More sharing options...
Canman2005 Posted July 12, 2008 Author Share Posted July 12, 2008 Thanks Barand But in the products table itself, should I store the category ID numbers in one field or have a field for main category, a field for a sub category and so on? Link to comment https://forums.phpfreaks.com/topic/114428-storing-product-information-advice-needed/#findComment-588500 Share on other sites More sharing options...
DarkWater Posted July 12, 2008 Share Posted July 12, 2008 Have a products table, a category table, and a category_associations table that stores all product associations. Link to comment https://forums.phpfreaks.com/topic/114428-storing-product-information-advice-needed/#findComment-588502 Share on other sites More sharing options...
Canman2005 Posted July 12, 2008 Author Share Posted July 12, 2008 and hold all the products and related categories in the category_associations table? if so, how do you suggest I store this data in the category_associations table? Link to comment https://forums.phpfreaks.com/topic/114428-storing-product-information-advice-needed/#findComment-588505 Share on other sites More sharing options...
Barand Posted July 12, 2008 Share Posted July 12, 2008 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 https://forums.phpfreaks.com/topic/114428-storing-product-information-advice-needed/#findComment-588591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.