目前我有一张这样的桌子:
+-----------+---------------+-------------+-------------+
| category | OrderID | Name | Name2 |
+-----------+---------------+-------------+-------------+
| ABC | 12345 | Pen | Black |
+-----------+---------------+-------------+-------------+
| ABC | 34545 | Pencil | White |
+-----------+---------------+-------------+-------------+
| ABC | 34545 | Pen | Black |
+-----------+---------------+-------------+-------------+
| DEF | 12345 | Pencil | Black |
+-----------+---------------+-------------+-------------+
| DEF | 12345 | Pen | White |
+-----------+---------------+-------------+-------------+
我喜欢树格式,我已经阅读了很多关于 ref 的示例。和递归,但没有掌握概念。有人可以帮忙吗?
由于表会很大 - 可能有大约 20K 条记录 - 不确定递归会对性能等产生任何影响。
由于客户端 html 小部件的限制,我必须以这种格式完成:
Array
(
[0] => Array
(
[category] => ABC
[children] => Array
(
[0] => Array(
[OrderID] => 12345
[children] => Array
(
[Name] => Pen
[Name2] => Black
)
)
[1] => Array(
[OrderID] => 34545
[children] => Array
(
[0] => Array(
[Name] => Pencil
[Name2] => White
)
[1] => Array(
[Name] => Pen
[Name2] => White
)
)
)
)
[1] => Array
(
[category] => DEF
[children] => Array
(
[OrderID] => 12345
[children] => Array
(
[0] => Array(
[Name] => Pencil
[Name2] => Black
)
[1] => Array(
[Name] => Pen
[Name2] => White
)
)
)
)