我已经将网站设置为有3列带图像,在图像下有标题,在标题下有描述x3。如果我使用php输入单词,一切都很好,但当我使用fetch数组时,它会打断列,并将每个列放在不同的行上。我当前的代码是:
<!-- /.row -->
<?
while($row = mysql_fetch_array($result)){
?>
<!-- Projects Row -->
<div class="row">
<div class="col-md-4 portfolio-item">
<a href="#">
<img class="img-responsive" src="../assets/img/tienda/<? echo $row["images"];?>" alt="">
</a>
<h3>
<a href="#"><? echo $row["top"];?></a>
</h3>
<p><? echo $row["desc"];?></p>
</div>
</div>
</div>
<hr>
<!-- /.row -->
<? } ?>
这个答案将处理PHP返回3个以上结果的可能性,这将需要另一行1-3个结果。您必须在CSS中添加一个.clearfix来清除:这两个选项都可以安全地清除col-md-4中包含的浮动……此外,确保浮动不会传播也是一个很好的做法。
<?
$inc = 0; //This is your incrementor
while($row = mysql_fetch_array($result)){
if ($inc == 0) {
?>
<div class="row">
<?
}
?>
<div class="col-md-4 portfolio-item">
<a href="#">
<img class="img-responsive" src="../link/<? echo $row["images"];?>" alt="">
</a>
<h3>
<a href="#"><? echo $row["top"];?></a>
</h3>
<p><? echo $row["desc"];?></p>
</div>
<?
if ($inc == 0} {
?>
<div class="clearfix"></div>
</div>
<?
}
$inc = ($inc == 2)? 0 : $inc++; //Increment unless value = 2, then set to zero
}
?>
<hr>
尝试
<!-- /.row -->
<div class="row">
<?
while($row = mysql_fetch_array($result)){
?>
<!-- Projects Row -->
<div class="col-md-4 portfolio-item">
<a href="#">
<img class="img-responsive" src="../assets/img/tienda/<? echo $row["images"];?>" alt="">
</a>
<h3>
<a href="#"><? echo $row["top"];?></a>
</h3>
<p><? echo $row["desc"];?></p>
</div>
<!-- /.row -->
<? } ?>
</div>
<hr>