如何使用php for循环在一张幻灯片滑块中一次显示两个项目,请帮助我,因为我已经编写了以下代码,请建议
for ($i=0;$i<=$num_logo-1;$i++){
$result_logo = db_fetch_row($qid_logo);
if($i== 0 ) {
echo "<div class=\"item active\" >\n";
echo"<div class=\"col-lg-6 col-md-6 col-sm-12 col-xs-12\" style=\"float:left; padding-right:10px; text-align:center;\">";
echo"<img src=\"images/winner_logo/".$result_logo[3]."\" class=\"img-responsive center-block\" ><br><b>".$result_logo[1]."</b>";
if(($i+1) % 2 == 0) {
echo "</div>";
echo "</div>";
}
} else {
echo "<div class=\"item\" >\n";
echo"<div class=\"col-lg-6 col-md-6 col-sm-12 col-xs-12\" style=\"float:left; padding-right:10px; text-align:center;\">";
echo"<img src=\"images/winner_logo/".$result_logo[3]."\" class=\"img-responsive center-block\" ><br><b>".$result_logo[1]."</b>";
echo"</div>";
echo "</div>\n";
}
}
答案 0 :(得分:0)
您可以使用数组块函数
<?php foreach (array_chunk($array, 2, true) as $column){ ?>
<div class="row"> <!--this will be outer area-->
<?php foreach ($column as $item){ ?>
<div class="col-md-6"> <!--this will be inner item area-->
<p></p>
</div>
<?php } ?>
</div> <!--this will be outer area closing-->
<?php } ?>
用您的引导div和内部区域替换外部区域和每个项目数据......:)