所以我想做的是在PHP中每3列打印一次,并用foreach循环的bootstrap列创建新行,这是我的代码
<div class = "row">
<?php foreach($location_list as $location)
{
echo "<div class ='col-md-4'>
<hr> $location->address </hr>
<hr> $location->name </hr>
<hr> $location->pin </hr>
</div> ";
}
?>
</div>
答案 0 :(得分:1)
在特定条件下,要打印的代码row
应该在foreach
循环内。并且打印行的条件应为:
<?php
foreach ($location_list as $key => $location) {
if ($key % 3 == 0) {
echo '<div class = "row">';
}
echo "<div class ='col-md-4'>
<hr> $location->address </hr>
<hr> $location->name </hr>
<hr> $location->pin </hr>
</div> ";
if ($key % 3 == 2) {
echo '</div>';
}
}
?>