foreach里面的foreach

时间:2015-12-30 10:19:13

标签: php codeigniter foreach

我有这段代码,很长很抱歉。

<ul id="org" style="display:none">
  <?php foreach ($note1 as $item1) { ?>
  <li>
    <?php echo $item1->Node_Id; ?>
    <?php foreach ($noteLevel1 as $item2) { ?>
      <p style="font-size:15px;padding:10px 5px 10px 0px"><?php echo $item2->LabelNote; ?></p>
      <div class="SmallBox" id="<?php echo $item2->DetailNode_id; ?>" style="margin-bottom:10px;">
        <input type="text" value="<?php if(empty($item2->Realisasi)) { echo ''; }else{  echo number_format($item2->Realisasi,0,",","."); } ?>" class="TextInput" />
        <input type="text" value="<?php if(empty($item2->Target)) { echo ''; }else{  echo number_format($item2->Target,0,",","."); } ?>" class="TextInput" />
        <input type="text" value="<?php if(!empty($item2->PercentRealisasi)) { echo $item2->PercentRealisasi.'%'; }else{ echo '0%'; } ?>" class="PercentInput" />
        <img class="circles4" src='http://localhost/CST/public/img/green.png' onload="this.onload=null; this.src=GetStatusImage(<?php echo $item2->PercentRealisasi; ?>);" />
      </div >
    <?php } ?>
    <div class="clearDiv"></div>
    <?php foreach ($note2 as $item3) { ?>
    <?php echo $item3->Node_Id.'T'.$item3->ParentNode; ?>
      <ul>
        <?php foreach ($noteLevel2 as $item4) { ?>
        <li>
          <p class="NodeLabel"><?php echo $item4->LabelNote; ?></p>
            <div id="<?php echo $item4->DetailNode_id; ?>" class="SmallBox">
              <center>
                <input type="text" value="<?php if(empty($item4->Realisasi)) { echo ''; }else{ echo number_format($item4->Realisasi,0,",",".");} ?>" class="TextInput" readonly="true"/>
                <input type="text" value="<?php if(empty($item4->Target)) { echo ''; }else{ echo number_format($item4->Target,0,",","."); } ?>" class="TextInput" readonly="true"/>
                <input type="text" value="<?php if(!empty($item4->PercentRealisasi)) { echo $item4->PercentRealisasi.'%'; }else{ echo '0%'; } ?>" class="PercentInput" readonly="true"/>
              <img class="circles" src='http://localhost/CST/public/img/green.png' onload="this.onload=null; this.src=GetStatusImage(<?php echo $item4->PercentRealisasi; ?>);" />
              </center>
            </div>
            <?php foreach ($note3 as $item5) { ?>
              <?php echo $item5->Node_Id.'T'.$item5->ParentNode; ?>
              <ul>
                <?php foreach ($noteLevel3 as $item6) { ?>
                <li>
                  <p class="NodeLabel"><?php echo $item6->LabelNote; ?></p>
                  <div id="<?php echo $item6->DetailNode_id; ?>" class="SmallBox">
                    <center>
                      <input type="text" value="<?php if(empty($item6->Realisasi)) { echo ''; }else{ echo number_format($item6->Realisasi,0,",",".");} ?>" class="TextInput" readonly="true"/>
                      <input type="text" value="<?php if(empty($item6->Target)) { echo ''; }else{ echo number_format($item6->Target,0,",","."); } ?>" class="TextInput" readonly="true"/>
                      <input type="text" value="<?php if(!empty($item6->PercentRealisasi)) { echo $item6->PercentRealisasi.'%'; }else{ echo '0%'; } ?>" class="PercentInput" readonly="true"/>
                      <img class="circles" src='http://localhost/CST/public/img/green.png' onload="this.onload=null; this.src=GetStatusImage(<?php echo $item6->PercentRealisasi; ?>);" />
                    </center>
                  </div>
                </li>
              <?php } ?>
              </ul>
            <?php } ?>
            </li>
          <?php } ?>
        </ul>
      <?php } ?>
    </li>
  <?php } ?>
</ul>

您可以在此图片中看到该表:

enter image description here

结果应该是这样的: enter image description here

我希望node_idnode_id相等时显示parent_node。但是当我尝试添加这样的代码时:

<?php foreach ($note3 as $item5) { ?>
  **<?php if($item5->ParentNode == $item3->Node_Id){ ?>**
    <?php echo $item5->Node_Id.'T'.$item5->ParentNode; ?>
    <ul>
      <?php foreach ($noteLevel3 as $item6) { ?>
      <li>
        <p class="NodeLabel"><?php echo $item6->LabelNote; ?></p>
        <div id="<?php echo $item6->DetailNode_id; ?>" class="SmallBox">
          <center>
            <input type="text" value="<?php if(empty($item6->Realisasi)) { echo ''; }else{ echo number_format($item6->Realisasi,0,",",".");} ?>" class="TextInput" readonly="true"/>
            <input type="text" value="<?php if(empty($item6->Target)) { echo ''; }else{ echo number_format($item6->Target,0,",","."); } ?>" class="TextInput" readonly="true"/>
            <input type="text" value="<?php if(!empty($item6->PercentRealisasi)) { echo $item6->PercentRealisasi.'%'; }else{ echo '0%'; } ?>" class="PercentInput" readonly="true"/>
            <img class="circles" src='http://localhost/CST/public/img/green.png' onload="this.onload=null; this.src=GetStatusImage(<?php echo $item6->PercentRealisasi; ?>);" />
          </center>
        </div>
      </li>
      <?php } ?>
    </ul>
  <?php } ?>
<?php } ?>

结果应该是这样的:

enter image description here

就像我只是循环数组的第一个索引一样。我该如何解决?

0 个答案:

没有答案