ryanfc Posted October 24, 2007 Share Posted October 24, 2007 ok i am creating a directory of local business and need a bit of help on something. I want to have it where a client can belong to more than 1 category or sub-category. The categories for example are Restaurants, Entertainment, etc. Then under Restaurants you have something like Greek, Italian, etc as the sub-categories. So I have 3 tables. The categories table with the cat title and id number. (there are only 7 categories) The sub categories table with the sub cat title, id number and the number of the category it belongs to. Then I have the client table that contains the client info such as business name, address, etc. In there I have a field for the category and sub category where I fill in the correct number. So if it is a restaurant (cat 1) and an Italian restaurant (sub cat 7) I fill in the correct fields with those numbers. Now with some clients I want to have them say under Restaurants and sub cat Italian and Caterers. When I try putting in 4,45 in the subcategories field of the client table it erases the ,45. So what can I do to fix this? (so that a client can belong to more than one sub-category. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/74646-multiple-categories/ Share on other sites More sharing options...
BlueSkyIS Posted October 24, 2007 Share Posted October 24, 2007 either fix your code and/or database so you can use comma-delimited values in a field or add a new table containing id, customer_id, category_id, subcategory_id. then use that table to tie everything together instead of storing comma-delimited values. Quote Link to comment https://forums.phpfreaks.com/topic/74646-multiple-categories/#findComment-377328 Share on other sites More sharing options...
cmgmyr Posted October 24, 2007 Share Posted October 24, 2007 you can do the same thing with just one table very easily. categories ======== id parentid category_name Quote Link to comment https://forums.phpfreaks.com/topic/74646-multiple-categories/#findComment-377329 Share on other sites More sharing options...
cmgmyr Posted October 24, 2007 Share Posted October 24, 2007 Here ya go...this will help you out a lot: http://www.phpfreaks.com/forums/index.php/topic,131506.0.html Quote Link to comment https://forums.phpfreaks.com/topic/74646-multiple-categories/#findComment-377335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.