1 回答
TA贡献1820条经验 获得超10个赞
移动while循环,使其在行元素内发生。
<section class="politique container">
<?php
$query="SELECT*FROM projekt WHERE arhiva=0 AND kategorija='politique' LIMIT 3";
$result=mysqli_query($dbo, $query);
echo'<article>';
echo '<div class="container">';
echo '<div class="row padding>';
while($row=mysqli_fetch_array($result)) {
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'</article>';
?>
</section>
此外,正如对您的问题的评论中提到的,有一种更简洁的方法可以在您的代码中混合使用 php 和 html;
<?php
$query="SELECT*FROM projekt WHERE arhiva=0 AND kategorija='politique' LIMIT 3";
$result=mysqli_query($dbo, $query);
?>
<section class="politique container">
<article>
<div class="container">
<div class="row padding">
<?php while ($row = mysqli_fetch_array($result)) { ?>
<div class="card col-md-4">
<img class="card-img-top" src="<?php echo UPLPATH.$row['slika'] ?>">
<div class="card-body">
<h6 class="card-title"><?php echo $row['naslov']; ?></h6>
</div>
<div class="ispod">
<?php echo $row['datum']; ?>
</div>
</div>
<?php } ?>
</div>
</div>
</article>
</section>
- 1 回答
- 0 关注
- 157 浏览
添加回答
举报