<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>
------------------------------------------------------------------------
答案 0 :(得分:0)
不确定您要实现的目标,但您的代码看起来很混乱:
试试这个:
<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>
------------------------------------------------------------------------
形成这一点,你的代码应该是可读的,然后你可以尝试解释你的问题