我有以下的foreach:顯示2分的結果通過DIV
<?php
foreach($result15 as $row15) {
$thumb15 = $row15->thumb;
$id15 = $row15->id_discografia;
?>
<div class='wrapper'>
<div class="album"><img src="img/<?php echo $thumb15; ?>" alt="" width="246" height="246"></div>
</div>
<?php } ?>
但是這樣只出現在每一個DIV .wrapper一個div .album。如何在每個div .wrapper中看到兩個div .album?
UPDATE
夥計們,找到了解決辦法:
<?php
$total = 0;
foreach($result15 as $row15){
$thumb15 = $row15->thumb;
$id15 = $row15->id_discografia;
if($total == 0){
echo '<div class="wrapper">';
}
?>
<div class="album" data-disco="disco<?php echo $id15; ?>">
<img src="img/<?php echo $thumb15; ?>" alt="" width="246" height="246">
</div>
<?php
$total = $total + 1;
if($total % 2 == 0){
echo '</div>';
$total = 0;
}
}
?>
嘗試在foreach循環中使用echo – blackuprise
@blackuprise我相信我需要一個計數器。但我不知道如何使用它 – user2433958