php - 使用 Div 显示 MySql 数据

标签 php html mysql twitter-bootstrap

如何显示来自mysql数据库的图片,特别是连续两张图片。我在 stack overflow 中阅读了很多文章,所有这些文章都使用 table 标签进行了讨论。但是我找不到任何使用 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.......

最佳答案

看起来你想使用 array_chunk .在发布此类内容之前,您可能需要检查一下,因为这似乎与以下内容重复/非常相似

PHP: display entries from Database in groups of five?

关于php - 使用 Div 显示 MySql 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21635794/

相关文章:

php - 在不使用 HTML 样式属性的情况下动态设置多个背景图像 url

php - 为什么我的 4 个 PHP 输入中只有 1 个正确写入数据库?

php - Internet Explorer Content-DIsposition 文件名不起作用

php - 从 Controller Symfony2 中的 URL 获取参数

html - CSS透明度使文本透明

javascript - HTML、Javascript 中的自定义事件

mysql - 我可以在 mysql 中的一个触发器声明中定义多个事件吗?

html - Bootstrap 移动菜单在切换后消失

mysql - 从 MYSQL 中提取日期

java - 使用 Spring JdbcTemplate 时如何动态更改数据库/目录