php mysql while loop slideshow

问题内容:

my code is

    <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;
    }

everything is ok and images working perfect but i cant display others row
like name

<h1><?php echo $show_products['name']; ?></h1>

first item name display and not change just first item name and images ok change

问题评论:

    
Show us the code that doesn’t work. Right now, there aren’t any <?php echo $show_products['name']; ?>.
    
<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>
– espooo
4 mins ago
    
Please update your question to contain all the relevant code instead. It’s pretty unreadable as a comment.
    
Also, look at the rendered html source and check if the names are outputted correctly (if it’s your HTML/CSS/JS that needs to be changed)

原文地址:

https://stackoverflow.com/questions/47756147/php-mysql-while-loop-slideshow

添加评论