【问题标题】:Trouble with html link tag and imagehtml链接标签和图片有问题
【发布时间】:2015-02-23 21:33:56
【问题描述】:

当我尝试使用 url 来图像时遇到了一些问题。

        <div class="col-lg-12">
        <h1 class="page-header">Anime!</h1>
    </div>

        <?php 

            include "config/database.php";

            $sql = "SELECT * FROM anime WHERE status = 'On Going' ORDER BY id";

            $query = mysql_query($sql);

            if ($query > 0){

        ?>  
    <div class="container">
            <div class="description-plate">
               <?php
                    while
                        ($row = mysql_fetch_array($query)){
                        $id = $row['id'];
                        $image = $row['image'];
                        $title = $row['title'];
                        $genre = $row['genre'];
                        $start = $row['start'];
                        $schedule = $row['schedule'];
                        $description = $row['description'];

                ?>
                <!--div class="caption-btm">
                    <p style="margin-left:6px; margin-top:175px;">Start Airing From:</p>
                    <h5 style="margin-left:10px;"><?php echo $start; ?></h5>
                    <p style="margin-left:6px;">Airing Schedule:</p>
                    <h5 style="margin-left:10px;"><?php echo $schedule; ?></h5>

                </div-->
                <div class="thumbnail-fluid">
                    <a href="<?php echo $row['image']; ?>">
                    <div id="og-plate">
                                <div><img src="admin/<?php echo $row['image'];  ?>"></div>
                    <?php } ?>
                    </div>
                    </a>
                </div>
            </div>
            <?php } ?>
    </div>

所以当我尝试使用 php 调用图像时,标签只出现在最后一张图像上。我想要做的是在每张图片上都有标签。非常感谢任何帮助,谢谢:)

【问题讨论】:

  • 看起来你在图像 div 之后有额外的&lt;?php } ?&gt;
  • @dfsq 这就是我发现的
  • 糟糕,请再次检查脚本。忘了粘贴完整的脚本,我的错 :)
  • 嗯,你在 &lt;a&gt;&lt;/a&gt; 标记的中间有那个右括号,即使现在你需要有 2 个是有道理的,但这仍然没有意义。
  • 谢谢艾琳!希望我能为您的回复赢得声誉,但似乎有人因为这个愚蠢的问题而减少了我的代表。 :)

标签: php html css image url


【解决方案1】:

现在你正在循环(不知道你为什么使用while)并且每次都在创建

        <div class="thumbnail-fluid">
            <a href="<?php echo $row['image']; ?>">
            <div id="og-plate">
                        <div><img src="admin/<?php echo $row['image'];  ?>"></div>
            <?php } ?>
            </div>
            </a>
        </div>

你想要做的是在每次通过附加下一个图像标签时构建一个 html 字符串,更像是

...

$myimages = '';    
   while  // skipped details
       $myimages .=   '  <div class="thumbnail-fluid">
                <a href=". $row['image'] .  '>
                <div id="og-plate">
                            <div><img src="admin/' . $row['image'] . '></div>'

                . '</div>
                </a>
            </div>';
}

【讨论】:

    【解决方案2】:

    它出现在最后一张图片,因为 ORDER BY id 和条件 status = 'On Going' 可以返回一张图片。你的html结构应该是这样的。

    <div class="col-lg-12">
        <h1 class="page-header">Anime!</h1>
    </div>
    
    <?php
    include "config/database.php";
    
    $sql = "SELECT * FROM anime WHERE status = 'On Going' ORDER BY id";
    
    $result = mysql_query($sql);
    $n = mysql_num_rows($result);
    if ($n > 0) {
        ?>  
        <div class="container">
            <div class="description-plate">
                <?php
                while ($row = mysql_fetch_array($result)) {
                    $id = $row['id'];
                    $image = $row['image'];
                    $title = $row['title'];
                    $genre = $row['genre'];
                    $start = $row['start'];
                    $schedule = $row['schedule'];
                    $description = $row['description'];
                    ?>
                    <div class="thumbnail-fluid">
                        <a href="<?php echo $row['image']; ?>">
                            <div id="og-plate">
                                <div><img src="admin/<?php echo $row['image']; ?>"></div>                    
                            </div>
                        </a>
                    </div>
                <?php } ?>
            </div>
    
        </div>
    <?php } ?>
    

    【讨论】:

      猜你喜欢
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多