PHP:连续数据库中的三个图像

时间:2017-04-06 18:28:07

标签: php twitter-bootstrap row

我想在一行中显示数据库中的三个图像。目前,所有图像都在垂直线上,我不知道如何修复它。任何帮助,将不胜感激。我只学习PHP,检查了其他问题,他们一直没有帮助。

我尝试过使用Bootstrap,但是也没用。我拥有它的方式确实连续显示3个,但是,如果我有查询$show_men="SELECT model, id, price,image FROM products WHERE id='id' "

,请在每一行中使用相同的产品
<div class="col-xs-12 col-sm-4">
    <!--selecting products from database and displaying. when user clicks on more info button, information is stored in array and displayed on item.php-->
    <?php
    include 'mysql.php';
    $show_men="SELECT model, id,  price,image FROM products WHERE cat='men' ";
    $query_men=mysqli_query($conn,$show_men);
    while($row=mysqli_fetch_array($query_men,MYSQLI_ASSOC)){
        echo '<br><br><table class="table"><tbody>
            <tr>
            <div><center><img class="img-responsive" src="../images/'.$row['image'].'" width="200" height="200"></center><br>
            <center><strong>'.$row['model'].'</strong><br><br><strong>Price:£    '.$row['price'].'</strong><br><br>
            <a href="../php/item.php?id1='.$row['id'].'" class="btn btn-default">More Info</a><br><br><strong></center></div><hr>
            </tr>
            </tbody>
            </table>';

    }?>
</div>

1 个答案:

答案 0 :(得分:0)

您需要迭代列而不是表..

    <div class="row">
            <?php

            include 'mysql.php';
             $show_men="SELECT model, id,  price,image FROM products WHERE cat='men' ";
             $query_men=mysqli_query($conn,$show_men);
              while($row=mysqli_fetch_array($query_men,MYSQLI_ASSOC)){
             echo '<div class="col-xs-12 col-sm-4"><br><br><table class="table"><tbody>
              <tr>
                <div><center><img class="img-responsive" src="../images/'.$row['image'].'" width="200" height="200"></center><br>
                <center><strong>'.$row['model'].'</strong><br><br><strong>Price:£    '.$row['price'].'</strong><br><br>
                <a href="../php/item.php?id1='.$row['id'].'" class="btn btn-default">More Info</a><br><br><strong></center></div><hr>
                </tr>
            </tbody>
            </table></div>';

             }
             ?>
     </div>