Programming in mysql: MySQL structure of website with parent and child topics on newest questions tagged mysql – Stack Overflow

I am building a website that has a parent/child structure for various topics. (Too explain it a bit more, it actually has 4 levels, so: parent < child < 2nd child < 3rd child) Currently I have a table for each level in MySQL. Each child has a row that refers to the parent’s id and primary key. The issue that I am having is that i see no way to create a list that shows the sub topics like that shown below:

Food
    Fruit
        Red
           Cherry
        Yellow
           Banana
    Meat
        Beef
        Pork

I have thought about using a single hierarchical table like that on: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ that i know can output a list like that.

However, the issue with that is that table could easily have millions of posts (assuming this gets of the ground) and a recursive function that sorts through it every time a page is requested seems like it would take a long time to load.

Although i recognize it is not a great question and answer site, I was wondering if anyone knew how Yahoo Answers stores their categories and subcategories as it seems similar to what I need to do. Are there any sites that have a category/subcategory database that anyone can provide information about?

If I want to have a list like that above, would I have to single hierarchical table (either adjacent list model or modified preorder tree structure) or could I just use php, sql, and javascript to create a list like that with what i currently have; that is 4 tables each for each level of child?

See Answers


source: http://stackoverflow.com/questions/11811979/mysql-structure-of-website-with-parent-and-child-topics
Programming in mysql: programming-in-mysql



online applications demo