dougui5419 2013-09-23 09:50
浏览 32

父子数组结构

I have right following code for to set Parent-Child Array Structure like..

$refs = array();
$list = array();

            while($QryRow_Category_sub = mysqli_fetch_assoc($QryResult_Category)) 
            {
                $thisref = &$refs[$QryRow_Category_sub['id']];

                $thisref['parent_id'] = $QryRow_Category_sub['parent_id'];
                $thisref['name'] = $QryRow_Category_sub['name'];

                if ($QryRow_Category_sub['parent_id'] == 0) {
                //echo &$thisref;
                    $list[$QryRow_Category_sub['id']] = &$thisref;
                } else {
                    $refs[$QryRow_Category_sub['parent_id']]['children'][$QryRow_Category_sub['id']] = &$thisref;
                }
            }

And this is my Output

   Television Cat - 1
      Television Cat - 1 Sub Cat - 1
      Television Cat - 1 Sub Cat - 2
   Television Cat - 2
      Television Cat - 2 Sub Cat - 1
   Television Cat - 3
      Television Cat - 3 Sub Cat - 1
   Television Cat - 4
      Television Cat - 4 Sub Cat - 1

   Television Cat - 1 Sub Cat - 1
   Television Cat - 1 Sub Cat - 2
   Television Cat - 2 Sub Cat - 1
   Television Cat - 3 Sub Cat - 1
   Television Cat - 4 Sub Cat - 1

This my code and i got the result good, but i have one problem with this. But i want to remove the following code from the output

Television Cat - 1 Sub Cat - 1
   Television Cat - 1 Sub Cat - 2
   Television Cat - 2 Sub Cat - 1
   Television Cat - 3 Sub Cat - 1
   Television Cat - 4 Sub Cat - 1

This is the duplicate entry of sub-category.

Please give a solution. Thank You.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看