我需要使用PHP从数据库中水平显示卡 我的代码在下面
function getHighlights($conn){0
$q = "SELECT *, MONTHNAME(date) AS themonth, DAYOFMONTH(date) AS theday, YEAR(date) AS theyear FROM highlights ORDER BY date DESC LIMIT 0,3";
$r = mysqli_query($conn, $q);
while($page = mysqli_fetch_assoc($r)){
echo '
<div class="container">
<div class="row-fluid">
<div class="card-deck mt-5 mb-4">
<div class="card col-md-6 col-lg-4 col-xs-12">
<img src="../thadd/images/'.$page['image'].'" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">'.$page['title'].'</h5>
<p class="card-text mb-5">'.$page['message'].'</p>
<div class="text-center mb-3">
<a href="#" class="btn btn-warning">Read More →</a>
</div>
<div class="card-footer text-muted">
Posted on Tuesday by '.$page['author'].'
</div>
</div>
</div>
</div>
</div>
</div>
';
}
答案 0 :(得分:0)
通常,将行移出循环,如下面的伪代码所示。
<div class="container">
<div class="row">
-- WHILE LOOP --
<div class="col">
-- OUTPUT DATA --
</div> <!-- col -->
-- END WHILE --
</div><!-- row -->
</div> <!-- container -->