0

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

5
  • It's just function fetch definition, where do you call it? Commented May 15, 2015 at 12:55
  • Why are you making the code that is suppose to display your items into a function? Further more, you aren't even using $table in your function. Commented May 15, 2015 at 12:55
  • function fetch is called from file index.php. when user clicks on the link Commented May 15, 2015 at 12:56
  • I was just testing the query that it is working or not so instead of $table which is the name of the table in the database , i wrote the name of the table Commented May 15, 2015 at 12:58
  • i am writing in function so i don't have to write the code again and again for every page Commented May 15, 2015 at 12:59

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

4 Comments

the function is called from index.php file my question is how to display col-sm-4 under col-sm-9 as it is showing the features item heading
Sure, you call the function at the end of page, so .col-sm-4 is shown there. If you need it here, forget on fetch function, just try the code above.
Thank you @panther "Sure, you call the function at the end of page"
Now i am calling where my function is and it is working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.