Jump to content

populating from db cause problem displaying images


williamh69

Recommended Posts

Hi guys i am populating products from db,  but the images does not showing sequentially, there are gaps between images ,,how i can fix this

this is my code:

<?php
$query = "SELECT * FROM products";
$select_products = mysqli_query($connection, $query);

while ($row = mysqli_fetch_assoc($select_products)){
$product_id = $row['product_id'];
$product_title = $row['product_title'];
$product_image = $row['product_image'];
$product_description = $row['product_description'];
$product_quantity = $row['product_quantity'];
$product_price = $row['product_price'];
$short_desc = $row['short_desc'];
?>
<div class="col-sm-4 col-lg-4 col-md-4">
                        <div class="thumbnail">
                            <img src="./images/<?php echo $product_image ?>" width="478" height="1034" alt="">
                            
                            <div class="caption">
                                <h4 class="pull-right">$<?php echo $product_price ?></h4>
                                <h4><a href="#"><?php echo $product_title ?></a>
                                </h4>
                                <p><?php echo $product_description ?>.</p>
                             </div>
                            
                            
                            <div class="ratings">
                                <p class="pull-right">18 reviews</p>
                                <p>
                                    <span class="glyphicon glyphicon-star"></span>
                                    <span class="glyphicon glyphicon-star"></span>
                                    <span class="glyphicon glyphicon-star"></span>
                                    <span class="glyphicon glyphicon-star"></span>
                                    <span class="glyphicon glyphicon-star-empty"></span>
                                </p>
                            </div>
                        </div>
                    </div>
<?php } ?>

capture-20200112-200626.png

Link to comment
Share on other sites

  • 2 weeks later...

 <img src="./images/<?php echo $product_image ?>" width="478" height="1034" alt="">

<?php echo $product_image ?> -make sure that name in db and acctual name of the image are the same

do you keep images in db or just a path?

Edited by MarkPhp2
Link to comment
Share on other sites

I personally find it easier to store the path and the filename in the database table, for example - assets/large/img-photos-1554932472.jpg. 

Then I simply do 

<img src="<?php echo $image ?>" width="478" height="1034" alt="">

 

Edited by Strider64
Added Example
Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.