Nested comments in PHP & MySQL

后端 未结 2 463
误落风尘
误落风尘 2020-12-09 00:02

I searched through the forums but couldn\'t get an authoritative answer. I want to implement a nested comment structure in a way like this:

    &l
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 00:38

    There are several different ways to store heirarchical data in MySQL. Check out Bill Karwin's presentation that demonstrates four options.

    • Adjacency List
    • Path Enumeration
    • Nested Sets
    • Closure Table

    You are using the adjacency list model for storing heirarchical data, but unfortunately this is the hardest model you could choose for querying subtrees.

    nested sets query subtree

    Your options are:

    • Change to a different model.
    • Restrict queries to n levels deep.
    • Use a stored procedure to query recursively. For more information about this, see Quassnoi's series of articles - Hierarchical queries in MySQL.

提交回复
热议问题