Hello to all,

I am trying to display the images on my page through php from mysql database

Problem is - Images are repeating , It always display only first image.

<?php include("header.php"); 
include("connection.php");
$sql = "select Image from flood_light";
$result = $conn -> query($sql);
if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {

    ?>
<!--header//-->
<div class="product-model">  
     <div class="container">
            <ol class="breadcrumb">
          <li><a href="index.html">Home</a></li>
          <li class="active">Products</li>
         </ol>

         <div class="col-md-9 product-model-sec">
                     <a href="single.html"><div class="product-grid">
                        <div class="more-product"><span> </span></div>                      
                        <div class="product-img b-link-stripe b-animate-go  thickbox">
                            <?php echo '<img src="images/'.$row[1].'"/>';   ?>
                            <div class="b-wrapper">
                            <h4 class="b-animate b-from-left  b-delay03">                           
                            <button><span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>Quick View</button>
                            </h4>
                            </div>
                        </div></a>                      
                        <div class="product-info simpleCart_shelfItem">
                            <div class="product-info-cust prt_name">
                                <h4>Flood Light</h4>                                

                                <div class="ofr">
                                  <p class="pric1"><del>Rs 280</del></p>

                                </div>
                                <input type="text" class="item_quantity" value="1" />
                                <input type="button" class="item_add items" value="ADD">
                                <div class="clearfix"> </div>
                            </div>                                              

                        </div>
                    </div>  

                     <a href="single.html"><div class="product-grid">
                        <div class="more-product"><span> </span></div>                      
                        <div class="product-img b-link-stripe b-animate-go  thickbox">
                            <?php echo '<img src="images/'.$row[2].'"/>';   ?>
                            <div class="b-wrapper">
                            <h4 class="b-animate b-from-left  b-delay03">                           
                            <button><span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>Quick View</button>
                            </h4>
                            </div>
                        </div></a>                  
                        <div class="product-info simpleCart_shelfItem">
                            <div class="product-info-cust prt_name">
                                <h4>Flood Light</h4>                                

                                <div class="ofr">
                                  <p class="pric1"><del>Rs 280</del></p>

                                </div>
                                <input type="text" class="item_quantity" value="1" />
                                <input type="button" class="item_add items" value="ADD">
                                <div class="clearfix"> </div>
                            </div>                      
                        </div>
                    </div>

                    <a href="single.html"><div class="product-grid">
                        <div class="more-product"><span> </span></div>                      
                        <div class="product-img b-link-stripe b-animate-go  thickbox">
                            <img src="images/flood3.jpg" class="img-responsive" alt=""/>
                            <div class="b-wrapper">
                            <h4 class="b-animate b-from-left  b-delay03">                           
                            <button><span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>Quick View</button>
                            </h4>
                            </div>
                        </div>  </a>                    
                        <div class="product-info simpleCart_shelfItem">
                            <div class="product-info-cust prt_name">
                                <h4>Flood Light</h4>                                

                                <div class="ofr">
                                  <p class="pric1"><del>Rs 280</del></p>

                                </div>
                                <input type="text" class="item_quantity" value="1" />
                                <input type="button" class="item_add items" value="ADD">
                                <div class="clearfix"> </div>
                            </div>                      
                        </div>
                    </div>

                    <a href="single.html"><div class="product-grid">
                        <div class="more-product"><span> </span></div>                      
                        <div class="product-img b-link-stripe b-animate-go  thickbox">
                            <img src="images/flood4.jpg" class="img-responsive" alt=""/>
                            <div class="b-wrapper">
                            <h4 class="b-animate b-from-left  b-delay03">                           
                            <button><span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>Quick View</button>
                            </h4>
                            </div>
                        </div></a>                      
                        <div class="product-info simpleCart_shelfItem">
                            <div class="product-info-cust prt_name">
                                <h4>Flood Light</h4>                                

                                <div class="ofr">
                                  <p class="pric1"><del>Rs 280</del></p>

                                </div>
                                <input type="text" class="item_quantity" value="1" />
                                <input type="button" class="item_add items" value="ADD">
                                <div class="clearfix"> </div>
                            </div>                      
                        </div>
                    </div>

                    <a href="single.html"><div class="product-grid">
                        <div class="more-product"><span> </span></div>                      
                        <div class="product-img b-link-stripe b-animate-go  thickbox">
                            <img src="images/flood5.jpg" class="img-responsive" alt=""/>
                            <div class="b-wrapper">
                            <h4 class="b-animate b-from-left  b-delay03">                           
                            <button><span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>Quick View</button>
                            </h4>
                            </div>
                        </div></a>                      
                        <div class="product-info simpleCart_shelfItem">
                            <div class="product-info-cust prt_name">
                                <h4>Flood Light</h4>                                
                                <!-- <span class="item_price">$187.95</span>     -->
                                <div class="ofr">
                                  <p class="pric1"><del>Rs 280</del></p>
                                <!--   <p class="disc">[12% Off]</p> -->
                                </div>
                                <input type="text" class="item_quantity" value="1" />
                                <input type="button" class="item_add items" value="ADD">
                                <div class="clearfix"> </div>
                            </div>                      
                        </div>
                    </div>

                    <a href="single.html"><div class="product-grid">
                        <div class="more-product"><span> </span></div>                      
                        <div class="product-img b-link-stripe b-animate-go  thickbox">
                            <img src="images/flood6.jpg" class="img-responsive" alt=""/>
                            <div class="b-wrapper">
                            <h4 class="b-animate b-from-left  b-delay03">                           
                            <button><span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>Quick View</button>
                            </h4>
                            </div>
                        </div></a>                      
                        <div class="product-info simpleCart_shelfItem">
                            <div class="product-info-cust prt_name">
                                <h4>Flood Light</h4>                                
                                <!-- <span class="item_price">$187.95</span>     -->
                                <div class="ofr">
                                  <p class="pric1"><del>Rs 280</del></p>
                                  <!-- <p class="disc">[12% Off]</p> -->
                                </div>
                                <input type="text" class="item_quantity" value="1" />
                                <input type="button" class="item_add items" value="ADD">
                                <div class="clearfix"> </div>
                            </div>                      
                        </div>
                    </div>

                    <a href="single.html"><div class="product-grid">
                        <div class="more-product"><span> </span></div>                      
                        <div class="product-img b-link-stripe b-animate-go  thickbox">
                            <img src="images/flood7.jpg" class="img-responsive" alt=""/>
                            <div class="b-wrapper">
                            <h4 class="b-animate b-from-left  b-delay03">                           
                            <button><span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>Quick View</button>
                            </h4>
                            </div>
                        </div></a>                      
                        <div class="product-info simpleCart_shelfItem">
                            <div class="product-info-cust prt_name">
                                <h4>Marvel Flood Light</h4>                             
                                <!-- <span class="item_price">$187.95</span>     -->
                                <div class="ofr">
                                  <p class="pric1"><del>Rs 280</del></p>
                                <!--   <p class="disc">[12% Off]</p> -->
                                </div>
                                <input type="text" class="item_quantity" value="1" />
                                <input type="button" class="item_add items" value="ADD">
                                <div class="clearfix"> </div>
                            </div>                      
                        </div>
                    </div>

                    <a href="single.html"><div class="product-grid">
                        <div class="more-product"><span> </span></div>                      
                        <div class="product-img b-link-stripe b-animate-go  thickbox">
                            <img src="images/flood8.jpg" class="img-responsive" alt=""/>
                            <div class="b-wrapper">
                            <h4 class="b-animate b-from-left  b-delay03">                           
                            <button><span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>Quick View</button>
                            </h4>
                            </div>
                        </div></a>                      

                        <div class="product-info simpleCart_shelfItem">
                            <div class="product-info-cust prt_name">
                                <h4>Regal Flood Light</h4>                              
                                <!-- <span class="item_price">$187.95</span>     -->
                                <div class="ofr">
                                  <p class="pric1"><del>Rs 280</del></p>
                                  <!-- <p class="disc">[12% Off]</p> -->
                                </div>
                                <input type="text" class="item_quantity" value="1" />
                                <input type="button" class="item_add items" value="ADD">
                                <div class="clearfix"> </div>
                            </div>
                        </div>
                    </div>
                    <a href="single.html"><div class="product-grid">
                        <div class="more-product"><span> </span></div>                      
                        <div class="product-img b-link-stripe b-animate-go  thickbox">
                            <img src="images/flood9.jpg" class="img-responsive" alt=""/>
                            <div class="b-wrapper">
                            <h4 class="b-animate b-from-left  b-delay03">                           
                            <button><span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>Quick View</button>
                            </h4>
                            </div>
                        </div></a>                      
                        <div class="product-info simpleCart_shelfItem">
                            <div class="product-info-cust prt_name">
                                <h4>Audi Flood Light</h4>                               
                                <!-- <span class="item_price">$187.95</span>     -->
                                <div class="ofr">
                                  <p class="pric1"><del>Rs 280</del></p>
                                 <!--  <p class="disc">[12% Off]</p> -->
                                </div>
                                <input type="text" class="item_quantity" value="1" />
                                <input type="button" class="item_add items" value="ADD">
                                <div class="clearfix"> </div>
                            </div>
                        </div>
                    </div>
            </div>
            <?php include("sidebar.php"); ?>

                          <!--script-->

<!---->
<div class="subscribe">
     <div class="container">
         <h3>Newsletter</h3>
         <form>
             <input type="text" class="text" value="Email" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email';}">
             <input type="submit" value="Subscribe">
         </form>
     </div>
</div>
<!---->
<?php 

}
} else {
    echo "0 results";
}
include("footer.php"); ?>

Maybe browser show cached images. Try generate different file names to output image

commented: Good point. Thing 1, Thing 2, etc. +12

Deleted cache already.
actually i am trying to fetch data from table and want to display on my web page.
But the issue is that Ist record of table is repeating every time, i am unable to access 2nd row of the table.

Member Avatar for diafol

If you can use fetch_all() - print_r the resulting array to see what data it holds.

Anyway you're using associated array data:

   while($row = $result->fetch_assoc()) {

But you're accessing data via numerical index:

$row[2]

This is my table:-

SELECT `Id`, `Name`, `Brand`, `Quantity`, `Detail`, `Unit`, `Color`, `Material`, `Image` FROM `flood_light` WHERE 1
Member Avatar for diafol

I don't see why the DB table matters - I was stating that you are retrieving an associated array, but trying to access it as a numerically-indexed array. Try using $row['Image'] instead of $row[2].

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.