Printing HTML dom inside PHP foreach loop

我试图使用Foreach循环对数据库中的每一行进行手风琴,但我尝试过这一点,但我只能在其所谓的手风琴上达到了2多个特遣队,所以在行上算上我尝试过的东西: –

 <?foreach ($fetchedDrafts as $draft):?>
                <div id="<?=$draft['name'];?>" role="tablist" class="border border-danger rounded" aria-multiselectable="true">

                    <div class="card">
                        <div class="card-header" role="tab" style="height:120px !important;" id="section1HeaderId">
                            <h5 class="mb-0">
                                <a data-toggle="collapse" data-parent="#accordianId" href="#section1ContentId" aria-expanded="true" aria-controls="section1ContentId">
                                <center>
                                <!---->
                                <button type="button" class="btn btn-warning pill" style="display:none;"><?$draft['name'];?></button>
                                <h3 class="Title" style="display:none;font-family:hana;"></h3>
                                </center>
                                <img class="accordianimg pull-left" style="width:180px; height:120px;" src="..\upload\gsk.png" alt="alt"></img>
                        </a>

                        <div class="input-container" style="margin-top:2rem !important; margin-right:6rem;">
                        <h2>
                        <button onclick="funvction()" class="btn btn-danger SearchButton"style="font-family:hana;">بحث</button>
                        <input class="border border-danger rounded SearchInput" type="text" style="width:440px;"id="SearchInput" placeholder="البحث عن المنتج" name="DraftSearchFiled" onchange="DraftSearch()">
                        </h2>
                        </div>
                        </div><br>


                        <div id="section1ContentId" class="collapse in" role="tabpanel" aria-labelledby="section1HeaderId" style="overflow-x: hidden !important;" onscroll="">
                        <div class="card-body d-flex flex-wrap">
                        <div class="row justify-content-center">
                        <div id="demo" class="carousel slide carousel" data-ride="carousel" style="margin-left:20rem;width: 26rem; height:31rem;">
                        <!-- no need for indicators -->

                        <div class="carousel-inner canner">
                        <?
                            $i = 0;
                            foreach($DRTitems  as $row){
                            $actives = '';
                            if($i == 0){
                            $actives ='active';
                            }
                            ?>
                        <div class="carousel-item  <?= $actives;?>">
                        <div class="container">
                        <div class="row justify-content-center">
                        <div class="card"  style="width: 26rem; height:auto;">
                        <? if($row['Sale'] == true){
                        echo'<div class="corner-ribbon top-left sticky shadow">تخفيض</div>';
                        }else{
                        echo'<div class="corner-ribbon top-left-green sticky shadow">افضل سعر</div>';
                        }
                        ?>
                        <img class="card-img-top" src="<?= $row['imageurl'] ?>" alt="Drug" style=""></img>
                        <div class="card-body body">
                            <h1 class="card-title Productname " style="font-family:Tahoma !important; font-size:42px !important;"><?= $row['name'] ?></h1><br><br><br>
                            <p class="chemicalcom"><?= $row['chemicalcom']?></p><br>
                            <p class="price"><?= $row['price'] ?>$</p>
                            <input type="submit" class="btn btn-success btn-sm btn-block btn" value="أضف للسلة"></input>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    <? $i++; }?>


</div>
  <?php endforeach; ?>

我在db中有3行,但代码只有一个手风琴

在第1行和一些其他线条之前,您在Foreach之前缺少PHP(或=)S_FRIX
你可以添加dbtag并添加你的sql也是如此。你试过跑步吗?sqlStatement并确认它返回正确的结果?NCXNAV

回答 0