【问题标题】:loop for three elements三个元素的循环
【发布时间】:2018-06-11 14:44:37
【问题描述】:

我有这个问题,我需要重复卡片 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 }} ?>

【问题讨论】:

    标签: php html pdo


    【解决方案1】:

    你必须为此嵌套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;
    

    你现在明白了,格式化代码。如果这有帮助,请投票

    【讨论】:

    • 好的,我知道你做了什么,我知道怎么做3张卡片,想法不在这里,看兄弟,在3个元素设置后,我需要制作另一张卡片- group 将另外 3 个元素放入其中,卡片在 card-group 内,并感谢提前。
    猜你喜欢
    • 2022-06-12
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 2021-08-24
    • 2021-08-24
    • 2022-01-21
    • 2017-10-07
    相关资源
    最近更新 更多