我的代码是
<div align="center">
<div id="imgGallary" class="container">
<?php $get_products = $conn->query("SELECT * FROM products"); while ($show_products = $get_products->fetch_assoc()) { ?>
<h1><?php echo $show_products['name']; ?></h1>
<img src="img/<?php echo $show_products['img']; ?>" alt="" width="100%" height="300" >
<?php } ?>
</div>
</div>
<script>
(function(){
var imgLen = document.getElementById('imgGallary');
var images = imgLen.getElementsByTagName('img');
var counter = 1;
if(counter <= images.length){
setInterval(function(){
images[0].src = images[counter].src;
console.log(images[counter].src);
counter++;
if(counter === images.length){
counter = 1;
}
},2000);
}
})();
</script>
.container{
position: relative;
width: 90%;
height: 300px;
border-radius: 5px;
border: 1px #00274F solid;
overflow: hidden;
}
一切都很好,图像工作正常,但我不能显示其他行 喜欢名字
<h1><?php echo $show_products['name']; ?></h1>
显示第一个项目名称,而不是仅更改第一个项目名称和图像确定更改