search

Home  >  Q&A  >  body text

数据库 - 多级分类如何遍历

现有一张表
表结构
Id,name,description,parent_id
一个分类下有多个子分类,每个子分类下又会有子分类,深度多达10层左右。
分类的排列也是不规则的,现在希望获得的结果如下:
水果

...

某草草某草草2798 days ago890

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-24 16:02:58

    It is best not to use recursive methods for this kind of infinite classification

    There is a relatively efficient solution (lvalue-rvalue solution) for classification information that changes little in the tree itself:
    http://ftp.nchu.edu.tw/MySQL/tech-resources/articles/hierarchical- data.html

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-04-24 16:02:58

    @Huijiewei is right. The conventional method is lvalue and rvalue. This is relatively easy to use. http://www.arkulo.com/2015/02/25/Hierarchical/ This is the Chinese article about this method. An article by , I hope it will be helpful to you~~

    reply
    0
  • Cancelreply