简体   繁体   English

PHP Codeigniter foreach崩溃

[英]PHP Codeigniter foreach collapse

I want to make this kind of collapse in my php. 我想在我的PHP中进行这种崩溃。 Here is an example: 这是一个例子:

 <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <a data-toggle="collapse" href="#collapse1">Heading</a> <div id="collapse1"> <a data-toggle="collapse" href="#collapse2"> Category </a> </div> <div id="collapse2">Items</div> 

I want to apply something like that, in here: 我想在这里应用类似的东西:

<?php
$i=1;foreach($itemlist as $value) {
    echo "<h3>Tower Type : ".$value['notower']."</h3><br>";

    foreach($value['items'] as $val) { ?>
      <?= "<h4>".$val['groupem']."</h4><br>"; ?>
      <table class ="table table-bordered table-hovered table-striped table-condensed">
        <thead>
          <th><?= "Item Name" ?></th>
          <th><?= "Value" ?>
        </thead>
        <tbody>
            <?php foreach($val['item'] as $v) :?>
            <tr>
                <td><?= $v['nm_detailem']?></td>
                <td><?= $v['em_value']?></td>
            </tr>
            <?php endforeach;?>
        </tbody>
      </table>
    <?php } ?>

<?php } ?>

How can I do that? 我怎样才能做到这一点? I'm stuck at where to put those href . 我被困在放置那些href

You could use the following: 您可以使用以下内容:

$sOutput = '';
foreach ( $aData as $sData){

     If($sOutput != ''){
         $sOutput .= '</div><div class="collapse hidden">';
     }
     $sOutput .= '<a href=""></a>';
}

If(count($sOutput) == 1 && $sOutput !== ''){$sOutput .= '</div>';}

Add to css: 添加到CSS:

.hidden{display:none;}

Your jQuery could be: 您的jQuery可能是:

$(".collapse").on('click', function(){
    $('.collapse').addClass('hidden');
    $(this).removeClass('hidden');
});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM