Php 我想通过从数据库中获取图像来移动滑块 url/“alt=”Image“style=”宽度:100%;高度:500px;"> ------------------------------------------------------------------------
不确定您想要实现什么,但您的代码看起来很混乱:Php 我想通过从数据库中获取图像来移动滑块 url/“alt=”Image“style=”宽度:100%;高度:500px;"> ------------------------------------------------------------------------,php,Php,不确定您想要实现什么,但您的代码看起来很混乱: 你应该把它格式化 在while循环之前打开一个div,然后在打开另一个div之前关闭它 这可能会起作用,但会使以后的阅读变得困难 你的图像的线条被完全弄乱了 试试这个: <div class="carousel-inner" role="listbox"> <div class="active item"> <?php $latest_work=mysqli_query($
- 这可能会起作用,但会使以后的阅读变得困难
<div class="carousel-inner" role="listbox">
<div class="active item">
<?php
$latest_work=mysqli_query($conn,"select * from banners where status=1");
while($latest_object= mysqli_fetch_object($latest_work)){
?>
<img src="<?=WEBSITE_URL?>url/<?php if(isset($latest_object->image))echo $latest_object->image;?>"alt="Image" style="width:100%;height:500px;">
</div>
<div class="item ">
<?php
}
?>
<div>
</div>
------------------------------------------------------------------------
------------------------------------------------------------------------
从这一点来看,您的代码应该是可读的,然后您可以尝试解释您的问题
<div class="carousel-inner" role="listbox">
<?php
$latest_work=mysqli_query($conn,"select * from banners where status=1");
// start a counter, at 1 to avoid confusion over 0 indexing
$i = 1;
while($latest_object= mysqli_fetch_object($latest_work)){
// here, we have a counter, so that we can add the 'active' class to the first itteration
if ($i == 1) {
// we are the first itteration, so the calss should be 'item active'
$class = 'item active';
} else {
// otherwise, its just 'item'
$class = 'item';
}
// increment our counter $i
$i++;
if(isset($latest_object->image)) {
$image = WEBSITE_URL . 'url/' . $latest_object->image
echo '<div class="'.$class.'">';
echo '<img src="'.$image.'" alt="Image" style="width:100%;height:500px;"> ';
echo '<div>';
} else {
// do something else
}
}
?>
</div>
------------------------------------------------------------------------