当我在DB中运行列表时,我需要打印出一个div,其中包含三个li。当我使用bootstrap时,我需要在.span4的第三列之后的每一行使用.row-fluid进行div。但是我在使用for循环工作时遇到了一些麻烦..这里是未触及的代码:< / p>
<div class="row-fluid">'
<ul class="thumbnails">
<?php
for($i=0; $i<count($rows); $i+=1){
?>
<!-- This is why sort by programme doesn't work - ID is not what I need -->
<li class="span4" id="<?php echo $rows[$i]['Class']; ?>">
<div class="thumbnail">
<img src="http://placehold.it/320x200" alt="ALT NAME">
<div class="caption">
<h3><?php echo $rows[$i]['Title']; ?></h3>
<?php if(!empty($rows[$i]["DateSold"])){ ?>
<span class="label label-warning" style="margin-bottom: 10px;">Book has been sold!</span>
<?php } ?>
<p>Seller: <?php echo $rows[$i]['FirstName'] . " " . $rows[$i]['LastName']; ?> </p>
<p>Email: <?php echo $rows[$i]['Email']; ?></p>
<p>Cost: <?php echo $rows[$i]['Cost']; ?></p>
<p>Condition: <?php echo $rows[$i]['BookCondition']; ?></p>
<p align="center">
<?php echo '<a href="#myModal' . $i . '" class="btn btn-primary btn-block" data-toggle="modal">View More information</a>' ?>
</p>
</div>
</div>
</li>
<!-- Modal -->
<?php echo'<div id="myModal' . $i . '" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">'; ?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Book information</h3>
</div>
<div class="modal-body">
<p>Title: <?php echo $rows[$i]['Title']; ?> </p>
<p>Seller: <?php echo $rows[$i]['FirstName'] . " " . $rows[$i]['LastName']; ?> </p>
<p>Email: <?php echo $rows[$i]['Email']; ?></p>
<p>Phone: <?php echo $rows[$i]['PhoneNumber']; ?></p>
<p>Condition: <?php echo $rows[$i]['BookCondition']; ?></p>
<p>Date added: <?php echo $rows[$i]['DateAdded']; ?></p>
<p>Class: <?php echo $rows[$i]['Class']; ?></p>
<p>Cost: <?php echo $rows[$i]['Cost']; ?></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
<?php
}
?>
</ul>
</div>
我需要在DB的每三次打印后围绕列表项的行流体的顶级父div。
答案 0 :(得分:2)
在第二次阅读中,似乎更像是你想要一个单独的DIV和UL中的每三个LI。在这种情况下,您可以使用array_chunk
。
<?php $chunks = array_chunk($rows, 3);
for ($i = 0; $i<count($chunks); $i++)
{
?> <div class="row-fluid"><ul class="thumbnails"> <?php
for ($j = 0; $j<count($chunks[$i]); $j++)
{
?> do your LIs in here <?php
}
?> </ul></div> <?php
}