循环三个元素

时间:2018-01-01 17:27:02

标签: php html pdo

我有这个问题,我需要重复3次卡,但如果超过3次,则必须创建新的卡组,另外3个元素 帮助

            <div id="service" class="text-center">
            <br/>
            <h2 class="display-1"><b title="Services provided by the site" class="initialism">Service</b></h2>
            <br/>
        </div>
            <?php
              if($stmt1->rowCount() > 0){

            for($j=0;$row=$stmt1->fetch(PDO::FETCH_ASSOC);$j++){
            ?>
        <div class="card-group">
               <?php

               for($i=0;$row=$stmt1->fetch(PDO::FETCH_ASSOC);$i++){
                 if ($i < 3){
                ?>
            <div class="card">
                <img class="card-img-top" src="style/img/homepage/homepageCardImageCap.svg" alt="Card image cap">
                <div class="card-body">
                    <h4 class="card-title">Card title</h4>
                    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
                </div>
            </div>
            <?php }}?>

        </div>
        <?php }} ?>

1 个答案:

答案 0 :(得分:0)

你必须为那个

嵌套for循环
$count = 0;
for($j=0;$row=$stmt1->fetch(PDO::FETCH_ASSOC);$j++){
<div class="card-group">
    for($count; $count == 3; $count++){
    <div class="card">
        <img class="card-img-top" src="style/img/homepage/homepageCardImageCap.svg" alt="Card image cap">
        <div class="card-body">
            <h4 class="card-title">Card title</h4>
            <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
        </div>
    </div>
    }

    $count = 0;

你现在得到的想法格式化代码。投票,如果这是有帮助的