使用Div显示MySql数据

时间:2014-02-07 19:04:05

标签: php html mysql twitter-bootstrap

如何从mysql数据库显示图像,特别是连续两个图像。我已经在堆栈溢出中阅读了很多文章,所有这些文章都使用表格标签进行了讨论。但我找不到任何使用div的文章。 这是我的SQL代码,它不完全正确。(显示图像,但顺序不正确):

$result=mysql_query("SELECT * FROM images WHERE tag='$tag' ");
while($info=mysql_fetch_array($result))
    {
        if($count==2) //two images per row
        {
           print "</div>";
           $count = 0;
        }
        if($count==0)
        print '<div class="row"><div class="col-md-6 col-sm-6 gallery-display">';
        ?>
    <figure>
            <a href="first-image.php">
                <img src="1.jpg" alt="Texture Paper" class="display-image">
            </a>
            <a href="first-image.php" class="figcaption">
                <h3>Texture Paper</h3>
            </a>
        </figure>

            <?php
        $count++;
        print '</div>';
    }
    if($count>0)
       print "";
    ?>

这应该如何编码!

<div class="row">
    <div class="col-md-4 col-sm-4 gallery-display">
        <figure>
            <a href="first-image.php">
                <img src="1.jpg" alt="Texture Paper" class="display-image">
            </a>
            <a href="first-image.php" class="figcaption">
                <h3>Texture Paper</h3>
            </a>
        </figure>
        <!--figure-->
    </div>
    <div class="col-md-4 col-sm-4 gallery-display">
        <figure>
            <a href="sec-image.php">
                <img src="2..jpg" alt="Photo (:" class="display-image">
            </a>
            <a href="sec-image.php" class="figcaption">
                <h3>Photo Caption</h3>
            </a>
        </figure>

    </div>
    <!--.gallery-display-->
<div class="row">
<div class="col-md-4 col-sm-4 gallery-display">
..........loop code continues.......

1 个答案:

答案 0 :(得分:0)

看起来您想使用array_chunk。您可能希望在发布此类内容之前检查一下,因为这似乎与

重复/非常相似

PHP: display entries from Database in groups of five?