dsjklb0205 2017-12-25 07:00
浏览 138

如何显示多级一对多关系树

How to loop all records and display all the respective children using HTML <ul></ul>? I tried using PHP Do While but stuck at only 1 level.

MySQL (select * from user)

enter image description here

Desired output

Tree View

enter image description here

List View

enter image description here

  • 写回答

2条回答 默认 最新

  • douque9815 2017-12-25 07:07
    关注

    The easy was is to do that with the help of array. Hope it helps.

    $data = array();
    foreach ($result as $item) {
        $key = $item['name']; // or $item['info_id']
        if (!isset($data[$key])) {
            $data[$key] = array();
        }
    
        $data[$key][] = $item;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题