ProjectAb
ProjectAb

Reputation: 65

Bootstrap columns not working when writing in php while loop

I am using bootstrap in my website but when i am adding php loop to show the products the products are shown at the end of the page instead of showing in the area 'product will show here'.

<div class="col-sm-9 padding-right">
<div class="features_items">
<h2 class="title text-center">Features Items</h2>
<?php
function fetch($table){
$result = mysqli_query($conn,"SELECT id ,name FROM menshirt");
while($row = mysqli_fetch_assoc($result)) {
echo 
'<div class="col-sm-4">
<h2>$56</h2>
p> '.$name =$row['name'].'</p>
<a href="#" class="btn btn-default add-to-cart"><i class="fa fa-cart">  </i>Add to cart</a>
</div>
</div>';
 }
mysqli_close($conn);}
?>
</div></div>

image file

Upvotes: 0

Views: 596

Answers (1)

pavel
pavel

Reputation: 27092

You only creates a function fetch which isn't called. And inside open less divs than closed.

<div class="col-sm-9 padding-right">
    <div class="features_items">
        <h2 class="title text-center">Features Items</h2>
        <?php

        $result = mysqli_query($conn,"SELECT id ,name FROM menshirt");
        while($row = mysqli_fetch_assoc($result)) {
            echo ' 
                <div class="col-sm-4">
                <h2>$56</h2>
                p> '. $row['name'] . '</p>
                <a href="#" class="btn btn-default add-to-cart"><i class="fa fa-cart">  </i>Add to cart</a>
                </div>
                <!--/div--> <!-- you opened one div, tried to close two -->
            ';
        }
        mysqli_close($conn);}

        ?>
    </div>
</div>

Upvotes: 1

Related Questions