使用 bootstrap 在同一行显示 3 篇文章

我使用 php 和 mysqli 数据库,我知道如何提取信息,但它总是把文章放在一起:

第1条

第二条

第三条

代替Article1,Article2,Article3

<section class="politique container">


    <?php

        $query="SELECT*FROM projekt WHERE arhiva=0 AND kategorija='politique' LIMIT 3";

        $result=mysqli_query($dbo, $query);


        while($row=mysqli_fetch_array($result))

        {



            echo'<article>';

                echo '<div class="container">';

                    echo '<div class="row padding>';

                        echo'<div class="col-md-12 ">';

                            echo '<div class="card col-md-4">';

                                    echo '<img  class="card-img-top" src="' . UPLPATH . $row['slika'] . '">';

                                    echo '<div class="card-body">';

                                        echo '<h6 class="card-title">';

                                            echo $row['naslov'];

                                        echo '</h6>';

                                    echo '</div>';

                                        echo'<div class="ispod">';

                                            echo $row['datum']; 

                                        echo '</div>'; 

                            echo '</div>';

                        echo '</div>';

                    echo '</div>';                 

                echo '</div>';

            echo'</article>';

        }?>

</section>

我在条件下每行只包含 3 篇文章,但不知何故,它每次都可能进入新容器,因此文章是一篇一篇的。


慕沐林林
浏览 163回答 1
1回答

拉莫斯之舞

移动while循环,使其在行元素内发生。<section class="politique container">&nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; $query="SELECT*FROM projekt WHERE arhiva=0 AND kategorija='politique' LIMIT 3";&nbsp; &nbsp; &nbsp; &nbsp; $result=mysqli_query($dbo, $query);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo'<article>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<div class="container">';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<div class="row padding>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while($row=mysqli_fetch_array($result)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<div class="card col-md-4">';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<img&nbsp; class="card-img-top" src="' . UPLPATH . $row['slika'] . '">';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<div class="card-body">';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<h6 class="card-title">';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $row['naslov'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '</h6>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '</div>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo'<div class="ispod">';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $row['datum'];&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '</div>';&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '</div>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '</div>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '</div>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo'</article>';&nbsp; &nbsp; &nbsp;?></section>此外,正如对您的问题的评论中提到的,有一种更简洁的方法可以在您的代码中混合使用 php 和 html;<?php&nbsp; $query="SELECT*FROM projekt WHERE arhiva=0 AND kategorija='politique' LIMIT 3";&nbsp; $result=mysqli_query($dbo, $query);?><section class="politique container">&nbsp; <article>&nbsp; &nbsp; <div class="container">&nbsp; &nbsp; &nbsp; <div class="row padding">&nbsp; &nbsp; &nbsp; &nbsp; <?php while ($row = mysqli_fetch_array($result)) { ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="card col-md-4">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img class="card-img-top" src="<?php echo UPLPATH.$row['slika'] ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="card-body">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h6 class="card-title"><?php echo $row['naslov']; ?></h6>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="ispod">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php echo $row['datum']; ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <?php } ?>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div>&nbsp; </article></section>
打开App,查看更多内容
随时随地看视频慕课网APP