如何使用引导列在PHP中连续显示图像和文本?

时间:2019-04-25 20:48:25

标签: javascript php html css sql

想在同一列中以5行显示图像和文本,但是在所提供的代码中,这并不能满足我的要求,因为当它们显示时,它们以行而不是列显示。感谢您的帮助。

此图像显示了屏幕上当前显示的内容...

https://imgur.com/b3uD0qT

我想要的是这个...

https://imgur.com/KbTanh2

<?php
    $select_stmt=$db->prepare("SELECT * FROM galeria ORDER BY id DESC;" );  //sql select query
    $select_stmt->execute();
    while($row=$select_stmt->fetch(PDO::FETCH_ASSOC))
    {
?>

<div class="container">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-6"><img src="upload/<?php echo $row['image']; ?>" class="imagem" style="height: 100px; weight: 100px;"></div>
            <div class="col-sm-6"><a id=""><?php echo $row['texto'];?></a></div>
        </div>
    </div>
</div>

<?php
}
?>

4 个答案:

答案 0 :(得分:1)

现在它正在工作。感谢大家的帮助。这是下面的代码。

<div class="container">
<div class="row">

<?php
    $select_stmt=$db->prepare("SELECT * FROM galeria ORDER BY id DESC;" );  //sql select query
    $select_stmt->execute();
    while($row=$select_stmt->fetch(PDO::FETCH_ASSOC))
    {
?>

        <div class="col-sm-2">
            <div class="col-sm-12"><img src="upload/<?php echo $row['image']; ?>" class="imagem" style="height: 100px; weight: 100px;"></div>
            <div class="col-sm-12"><a id=""><?php echo $row['texto'];?></a></div>
        </div>

<?php
}
?>

</div>
</div>

答案 1 :(得分:0)

您只需要使用每个图像来构建项目。容器保持在循环之外。

    <div class="container">

    <?php
        $select_stmt=$db->prepare("SELECT * FROM galeria ORDER BY id DESC;" );  //sql select query
        $select_stmt->execute();
        while($row=$select_stmt->fetch(PDO::FETCH_ASSOC))
        {
    ?>
<div class="col-sm-2">
            <div class="row">
                <div class="col-sm-12"><img src="upload/<?php echo $row['image']; ?>" class="imagem" style="height: 100px; weight: 100px;"></div>
                <div class="col-sm-12"><a id=""><?php echo $row['texto'];?></a></div>
            </div>
</div>
    <?php
    }
    ?>

    </div>

答案 2 :(得分:0)

您不应每行创建一个容器。只有一个包含所有行的容器
将您的代码更改为此:

<div class="container">
<?php
    $select_stmt=$db->prepare("SELECT * FROM galeria ORDER BY id DESC;" );  //sql select query
    $select_stmt->execute();
    while($row=$select_stmt->fetch(PDO::FETCH_ASSOC))
    {
?>

    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-6"><img src="upload/<?php echo $row['image']; ?>" class="imagem" style="height: 100px; weight: 100px;"></div>
            <div class="col-sm-6"><a id=""><?php echo $row['texto'];?></a></div>
        </div>
    </div>


<?php
}
?>
</div>

答案 3 :(得分:0)

我的方式

 <div class="col-md-3 col-sm-6 col-xs-12">

    <a href="/images/<?php echo... 

      </div>

<div style="float: left; margin-left: 20px; margin-top: 10px;">

    <a href="/images/<?php echo...

        </div>