简体   繁体   English

2级重复项

[英]Repeatitive Items on Level 2

I have a page that displays an organizational tree however in level 2 there are repeated items. 我有一个页面显示组织树,但是在第2级中有重复的项目。 What I wanted to is to avoid the duplicates... 我要避免的是重复...

Here's the example display: 这是示例显示:

<ul id="org" style="display: none;">
<li>Brit School                        
    <ul>
        <li>Amy Winehouse
            <ul>
                <li>Carina Round</li>
            </ul>
        </li>
        <li>Adele Adkins
            <ul>
                <li>Kreayshawn K</li>
                <li>Leona Lewis</li>
            </ul>
        </li>
        <li>Adele Adkins
            <ul>
                <li>Kreayshawn K</li>
                <li>Leona Lewis</li>
            </ul>
        <li>Arctic Monkey
            <ul>
                <li>PJ Harvey</li>
            </ul>
        </li>
    </ul>

</li>

I wanted to omit the 2nd record Adele this is my example code in PHP 我想省略第二条记录Adele,这是我的PHP示例代码

<ul id="org" style="display: none;">
<?php foreach ($lvl1 as $genesA) {?>
    <li>
        <?php echo $genesA->LevelFullName1?>
        <?php if($genesA->lvlMemF) {?>
        <ul>
        <?php if($genesA->lvlMemF) {?>
            <?php foreach ($lvl2 as $genesB) {?>
                <?php if($genesB->lvlMemS) {?>
                <li><?php echo $genesB->LevelFullName2 ?>
                <?php if($genesB->lvlMemS) {?>
                  <ul>
                    <?php if($genesB->lvlMemS) {?>
                        <?php foreach ($lvl3 as $genesC) {?>
                            <?php if($genesB->lvlMemS == $genesC->referrerLvl3) {?>
                                <li>
                                    <?php echo $genesC->LevelFullName3?>
                                </li>
                            <?php } ?>
                        <?php } ?>
                    <?php } ?>
                  </ul>
                  <?php } ?>
                </li>
                <?php } else { ?>

                <?php } ?>
            <?php } ?>
        <?php } ?>
        </ul>

        <?php }?>
    </li>
<?php } ?>

I'm not so sure if I am heading on the right track I just want a dirty fix that's all :) 我不确定是否要朝正确的方向前进,我只想要一个肮脏的解决方案,就这样:)

that should do it: 应该这样做:

<?php
$seen = array();
?>
<ul id="org" style="display: none;">
<?php foreach ($lvl1 as $genesA) {?>
    <li>
        <?php echo $genesA->LevelFullName1?>
        <?php if($genesA->lvlMemF) {?>
        <ul>
        <?php if($genesA->lvlMemF) {?>
            <?php foreach ($lvl2 as $genesB) {?>
                <?php if($genesB->lvlMemS) {?>
                <li><?php echo $genesB->LevelFullName2 ?>
                <?php if($genesB->lvlMemS) {?>
                  <ul>
                    <?php if($genesB->lvlMemS) {?>
                        <?php foreach ($lvl3 as $genesC) {?>
                            <?php if($genesB->lvlMemS == $genesC->referrerLvl3) {?>
                                <?php if(!in_array($genesC->LevelFullName3, $seen)?>
                                <li>
                                    <?php echo $genesC->LevelFullName3?>
                                    <?php $seen[] =$genesC->LevelFullName3;?>
                                </li>
                                <?php }?>
                            <?php } ?>
                        <?php } ?>
                    <?php } ?>
                  </ul>
                  <?php } ?>
                </li>
                <?php } else { ?>

                <?php } ?>
            <?php } ?>
        <?php } ?>
        </ul>

        <?php }?>
    </li>
</ul>

you might want to check if my if is at the right place there because it could be that you get empty ul blocks if all the names already were seen. 您可能要检查my if是否在正确的位置,因为如果已经看到所有名称,则可能是空的ul块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 计算遍历树项目级别 - Calculating Treversal Tree items level 一个简单的待办事项应用程序的AJAX重复值php - AJAX repeatitive values php for a simple to-do app Mysql-在层次结构中查询最多只能达到第2级的项目 - Mysql- Query items that are up to only 2nd level in hierarchy Php Json Decode - 显示二级项的值 - Php Json Decode - Display value of second level items 如何计算嵌套在第二级 groupBy 中的项目? - How to count items that are nested inside a second level groupBy? 计算属于MYSQL中某个较高级别树的多级别类别树中的项目 - counting items from a multi level category tree that belong to a certain upper level tree in MYSQL Laravel 集合多级组通过插入新项目而不检查每个级别的键 - Laravel collection multi level groupBy insert new items without checking each level's key PHP递归函数/循环确定菜单,项目等的最低级别 - PHP Recursive Function/Loop to determine lowest level(s) of menus, items etc Divi Wordpress 主题:父级最高级别不可点击且不链接到移动菜单上的页面并折叠嵌套项目 - Divi Wordpress Theme: Top Parent Level Not Clickable & Does not Link to Page on Mobile Menu with Collapse Nested Items Magento 是否允许按国家/地区对产品级别的特定商品进行订购和运输限制? - Does Magento allow order and shipping restrictions by country for specific items on the product level?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM