gpt4 book ai didi

php - 循环以将图像从数据库一张一张显示到 Bootstrap 轮播中

转载 作者:可可西里 更新时间:2023-10-31 23:38:32 27 4
gpt4 key购买 nike

尝试在 codeigniter 的 foreach 循环中显示来自数据库的轮播图像。下面的代码一次显示所有图像。如何在 slider 内一张一张地显示图像?下一个和上一个按钮也不起作用?

<div id="myCarousel" class="carousel slide carousel-fade" data-ride="carousel">

<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>

<div class="carousel-inner" role="listbox">

<?php $i = 1; ?>
<?php $item_class = ($i == 1) ? 'item active' : 'item'; ?>
<div class="<?php echo $item_class; ?>">=
<a href="#">
<?php foreach ($m->result() as $row) :
$Player=$row->image;
echo "<img src='http://opunletter.com/" . $Player . "'";
?>
</a>
</div>
<?php $i++; ?>
<?php endforeach; ?>

</div>

<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>

<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>

</div><!-- /.carousel -->

最佳答案

<?php
$i = 1;
foreach ($m->result() as $row) {
$Player = $row->image;
$item_class = ($i == 1) ? 'item active' : 'item';
?>
<div class="<?php echo $item_class; ?>">
<a href="#">
<img src="http://opunletter.com/<?php echo $Player; ?>" />
</a>
</div>
<?php
$i++;
}
?>

您需要将 div.item 保持在循环中以包含每个单独的图像。

关于php - 循环以将图像从数据库一张一张显示到 Bootstrap 轮播中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33969611/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com