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? Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment 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! 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.