coolphpdude Posted September 4, 2008 Share Posted September 4, 2008 hi there, Im creating a school database system and i will use a number of categories, sub categories and sub sub categories. wot i am wondering is, what is the best way to do this? Should i have a table of main gategories then a table for each sub category like the following... i'll use a car database as an example... [b]Main_cat_table[/b] Ford Vauxhall Vauxwagon etc... [b]ford_sub_cat_table[/b] Focus Mondeo Fiesta etc... [b]vauxhall_sub_cat_table[/b] astra corsa vectra etc... [b]vauxwagon_sub_cat_table[/b] golf polo passatt etc... [b]golf_sub_cat_table[/b] tdi gt tdi gti Is this the best way to do it or am i making things difficult for me by making loads of tables??? Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 4, 2008 Share Posted September 4, 2008 If you are dealing with a finite number of sub-categories such as your example above, then separate tables make the most sense. Especially since each "category" may need different supporting information. However, if your subcategories will be infinite (such as a geneology solution) you will use one table. If this is the route you need to go, look for a tutorial - her is one: http://www.codeassembly.com/How-to-display-infinite-depth-expandable-categories-using-php-and-javascript/ Quote Link to comment Share on other sites More sharing options...
coolphpdude Posted September 4, 2008 Author Share Posted September 4, 2008 ooh that luks gud!!! it looks like exactly what i need. could you give me some further advice... if i use the method on that page id have something along the following Id Cat Parent 1 ford 0 2 vauxhall 0 3 vauxwagon 0 4 focus 1 5 fiesta 1 6 mondeo 1 7 astra 2 8 corsa 2 9 vectra 2 10 golf 3 11 polo 3 12 passatt 3 13 st 4 14 tdi 4 15 tdci 4 is that right?? so basically i am saying that id 13,14 and 15 (st, tdi, tdci) belong to id 4 (focus)? So would you recommend this way of doing things or do you think each category should have its own table? Quote Link to comment Share on other sites More sharing options...
coolphpdude Posted September 4, 2008 Author Share Posted September 4, 2008 bump Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 5, 2008 Share Posted September 5, 2008 is that right?? so basically i am saying that id 13,14 and 15 (st, tdi, tdci) belong to id 4 (focus)? Yes. So would you recommend this way of doing things or do you think each category should have its own table? I think I already answered that. If you have a finite number of categories like you showed in your example, then three separate tables would be better (e.g. Make, Model, Sub-Model?). Because in that example each category is a unique type of entity (make = manufacturer of the car, model = type of car, etc.) however, with something like a geneology database youhave many parent/child combinations similar to many categories, but each entity is stil the same type of object (a person). Since you did not explain the type of records you plan to record I can't really provide any concrete advice. Quote Link to comment 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.