keldorn Posted November 8, 2009 Share Posted November 8, 2009 I'm able to easily create categories, but I run into problems trying to think of ways to create sub-categories of a category in a sql database, how can this be done in the most efficient way? This is how I would do with no sub categories. Say you an article table, that holds say articles. Okay you have: id+cat_id+content++++++++++++title 1+1------This is your first post+ Hello world Then you have another table called categories, where you have this, id+name 1+foo bar Doing this you can easily after a mysql query take the cat_id, then say, SELECT name FROM category_table WHERE id=1) You will get Foo bar. I belive this is called recurvsive naming, where the article table only holds the ID number of the category, which translates to name in category_table. But things to me, get more confusing when designing sub-categories. So what is the best way to design the tables using sub categories? Quote Link to comment https://forums.phpfreaks.com/topic/180793-what-is-a-good-way-to-design-categories-in-a-database/ Share on other sites More sharing options...
xtopolis Posted November 9, 2009 Share Posted November 9, 2009 This might address your question: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html Quote Link to comment https://forums.phpfreaks.com/topic/180793-what-is-a-good-way-to-design-categories-in-a-database/#findComment-954333 Share on other sites More sharing options...
keldorn Posted November 12, 2009 Author Share Posted November 12, 2009 This might address your question: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html Hey thanks for the link. Just what I need. I was looking over wordpress how they set it up, its much in the same way. Quote Link to comment https://forums.phpfreaks.com/topic/180793-what-is-a-good-way-to-design-categories-in-a-database/#findComment-956102 Share on other sites More sharing options...
keldorn Posted November 22, 2009 Author Share Posted November 22, 2009 The link didn't really help actually, I've spent the past 2 nights tyring to figure this out myself. (I love a problem). So far I got this. Which works. I've added now a Depth to the table, Somehow I will use that to create a tree structure of the whole parent node. haha I bet no one here can figure out this works? Its like almost like binary. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/180793-what-is-a-good-way-to-design-categories-in-a-database/#findComment-963082 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.