Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Mehrstufige For-Schleife in PHP

Nach langem Nachdenken habe ich eine Logik erstellt, die perfekt zu meinen Bedürfnissen passt. Die Daten werden im Akkordeon richtig verteilt. Aber die Akkordeon-Panels sind nicht standardmäßig eingeklappt. Dazu mache ich eine neue Frage. Hier ist der Link

 <?php 
            $fistForLoopEnds = false;
            $secondForLoopEnds = false;
            $thirdForLoopEnds = false;
            $fourthForLoopEnds = false;
             ?>
          <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
           <?php foreach ($this->data2['distinct'] as $key) { ?>

          <div class="panel panel-<?php if ($fistForLoopEnds != true) {
              echo "danger";
              $panelId = "headingOne";
              $accodianId = "collapseOne";
              $accordionExpanded = "true";
          } elseif ($fistForLoopEnds == true && $secondForLoopEnds != true) {
              echo "warning";
              $panelId = "headingTwo";
              $accodianId = "collapseTwo";
              $accordionExpanded = "false\" class=\"collapsed";
          } elseif ($fistForLoopEnds == true && $secondForLoopEnds == true && $thirdForLoopEnds != true) {
              echo "info";
              $panelId = "headingThree";
              $accodianId = "collapseThree";
              $accordionExpanded = "false\" class=\"collapsed";
          } else { echo "success";
              $panelId = "headingFour";
              $accodianId = "collapseFour"; 
              $accordionExpanded = "false\" class=\"collapsed";
              }?>">
            <div class="panel-heading" role="tab" id="<?php echo $panelId; ?>">
              <h4 class="panel-title">
                <a role="button" data-toggle="collapse" data-parent="#accordion" href="#<?php echo $accodianId; ?>" aria-expanded="<?php echo $accordionExpanded; ?>" aria-controls="<?php echo $accodianId; ?>">
                  <?php echo $key->sidebar_category; ?>
                </a>
              </h4>
            </div>
            <div id="<?php echo $accodianId; ?>" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="<?php echo $panelId; ?>">
              <div class="panel-body">
            <?php 
                if ($fistForLoopEnds != true) {
                    foreach ($this->data2['results_railways'] as $key) { ?>
                        <h5><a href="<?php echo base_url(); ?>home/railways/<?php echo $key->post_id; ?>"><?php echo $key->sidebar_title; ?></a></h5>
                    <?php }
                    $fistForLoopEnds = true;
                    goto a;
                } 
                elseif ($secondForLoopEnds != true) {
                    foreach ($this->data2['results_ssc'] as $key) { ?>
                         <h5><a href="<?php echo base_url(); ?>home/ssc/<?php echo $key->post_id; ?>"><?php echo $key->sidebar_title; ?></a></h5>
                     <?php  }
                    $secondForLoopEnds = true;
                    goto a;
                }
                elseif ($thirdForLoopEnds != true) {
                    foreach ($this->data2['results_banks'] as $key) { ?>
                         <h5><a href="<?php echo base_url(); ?>home/banks/<?php echo $key->post_id; ?>"><?php echo $key->sidebar_title; ?></a></h5>
                     <?php  }
                    $thirdForLoopEnds = true;
                    goto a;
                }
                elseif ($fourthForLoopEnds != true) {
                    foreach ($this->data2['results_upsc'] as $key) { ?>
                         <h5><a href="<?php echo base_url(); ?>home/upsc/<?php echo $key->post_id; ?>"><?php echo $key->sidebar_title; ?></a></h5>
                     <?php  }
                    $fourthForLoopEnds = true;
                    goto a;
                }
                a:
             ?>
              </div>
            </div>
          </div>
           <?php } ?>
          </div>