liamloveslearning Posted May 11, 2010 Share Posted May 11, 2010 Hi all, I need to produce a table holding a list of categories, On my page, depending on the user_level they can choose x amount of categories. Can I ask whats the most efficient way of achieving this? parent_categories (id, name) secondary_categories (id, parent_id, name) member_plan (member_id, member_categories) The above is my theoretical idea of how it should look, what are your thoughts? Link to comment https://forums.phpfreaks.com/topic/201426-predefined-categories-table/ Share on other sites More sharing options...
ignace Posted May 12, 2010 Share Posted May 12, 2010 x amount of categories How do you exactly mean? x amount of total (parents + sub)? or x amount of parent? or x amount of sub? Link to comment https://forums.phpfreaks.com/topic/201426-predefined-categories-table/#findComment-1056971 Share on other sites More sharing options...
liamloveslearning Posted May 12, 2010 Author Share Posted May 12, 2010 X amount of sub, So on signup they click there primary category, and then there given the option to pick a sub, and its repeated if this makes sense? Link to comment https://forums.phpfreaks.com/topic/201426-predefined-categories-table/#findComment-1056973 Share on other sites More sharing options...
ignace Posted May 12, 2010 Share Posted May 12, 2010 and its repeated if this makes sense? You mean a Sub under a Sub under a Sub under a Sub ..? Most use the Adjacency List Model although there are better alternatives like a Binary Tree: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html Link to comment https://forums.phpfreaks.com/topic/201426-predefined-categories-table/#findComment-1056979 Share on other sites More sharing options...
liamloveslearning Posted May 12, 2010 Author Share Posted May 12, 2010 Hi Ignace, No only 1 sub, There will be 2 dropdowns... [Primary Category] - [sub Category] When both are selected another option below will appear such as [Musician] - [Cover Band] <--- selected option Primary Category - Sub Category <--- Second option now appears. I just need advice on how to best store these selected categoris in a table? Hope this isnt too confusing! Link to comment https://forums.phpfreaks.com/topic/201426-predefined-categories-table/#findComment-1057041 Share on other sites More sharing options...
ignace Posted May 12, 2010 Share Posted May 12, 2010 Your setup should do it: categories (id, name) subcategories (id, category_id, name) Just perform a SELECT count(*) FROM subcategories to see how many subcategories a user has left to create. Link to comment https://forums.phpfreaks.com/topic/201426-predefined-categories-table/#findComment-1057130 Share on other sites More sharing options...
liamloveslearning Posted May 12, 2010 Author Share Posted May 12, 2010 Briliant, Thanks again for all your help ignace! Link to comment https://forums.phpfreaks.com/topic/201426-predefined-categories-table/#findComment-1057145 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.