数据库文件xd_item:
id pid item lead ...
1 0 标题名称一
2 0 标题名称二
3 1 中标题名称1-1
4 1 中标题名称1-2
5 2 中标题名称2-1
6 2 中标题名称2-2
8 3 小标题名称1-1-1
9 6 小标题名称2-2-1
10 6 小标题名称2-2-2
11 2 中标题名称2-3
---------------------
输出效果:
序号 项目名称
1 标题名称一
1.1 中标题名称1-1
1.1.1 小标题名称1-1-1
1.2 中标题名称1-2
2 标题名称二
2.1 中标题名称2-1
2.2 中标题名称2-2
2.2.1 小标题名称2-2-1
2.2.2 小标题名称2-2-2
2.3 中标题名称2-3
============================
要在PHP实现这个输出效果,要怎么实现呢?
First query those whose pid is 0, traverse those whose pid is 0, query those whose pid is the id of these items, and then output in a loop
If it is Oracle, you can use level() and sys_connect_by_path() functions to implement it.
If you do not use functions, you can build a view to implement it.
This is a reference to my method, which uses recursion to traverse. As long as it deals with data structures, there are methods, it just depends on the efficiency
Query the data using function calls. The first one perfectly supports your needs, and the second one is recursive storage of data