【问题标题】:Display MySql Data Using Div使用 Div 显示 MySql 数据
【发布时间】:2014-02-07 19:04:04
【问题描述】:

如何显示来自 mysql 数据库的图像,特别是连续显示两个图像。我已经阅读了很多关于堆栈溢出的文章,所有这些文章都使用 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.......

【问题讨论】:

  • 使用proper SQL escaping要非常小心,避免严重的SQL injection bugsmysql_query 很难正确使用,不应在新应用程序中使用。这是一个已弃用的接口,已从 PHP 的未来版本中删除。像 PDO is not hard to learn 这样的现代替代品,是一种更安全的查询方式。
  • zurb-foundation一样使用任何CSS框架
  • 能否建议替换代码以连续显示两张图片?

标签: php html mysql twitter-bootstrap


【解决方案1】:

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

重复/非常相似

PHP: display entries from Database in groups of five?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-20
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多