在php循环中写入时,引导列不起作用

时间:2015-05-15 12:51:52

标签: php html twitter-bootstrap

我在我的网站上使用bootstrap但是当我添加php循环以显示产品时,产品显示在页面的末尾,而不是在该区域中显示'产品将在此处显示'。

<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

1 个答案:

答案 0 :(得分:1)

您只创建一个未调用的函数fetch。内部开放少于div而非关闭。

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