Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Multi level untuk loop di PHP

Setelah banyak berpikir, saya telah membuat logika yang sesuai dengan kebutuhan saya dengan sempurna. Data akan tersebar di accordian dengan benar. Tetapi panel akordeon tidak diciutkan secara default. Saya membuat pertanyaan baru untuk itu. Ini Tautan

 <?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>



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana cara memeriksa NULL di MySqlDataReader dengan nama kolom?

  2. Format angka menjadi 2 tempat desimal

  3. Pengaturan server Web dan Database untuk mendapatkan zona waktu UTC dengan benar

  4. Masalah dengan Data Kueri dalam Tabel

  5. Bagaimana Anda mendapatkan banyak hasil dari satu CallableStatement?