麻烦的HTML链接标记和图像

时间:2014-12-26 16:17:03

标签: php html css image 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调用图像时,标记仅出现在最后一个图像上。我要做的是在每张图片上都有标签。非常感谢任何帮助,谢谢:)。

2 个答案:

答案 0 :(得分:0)

现在你正在完成循环(不确定为什么要使用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>';
}

答案 1 :(得分:0)

它出现在最后一张图片上,因为ORDER BY ID和条件状态=&#39; On Going&#39;可以返回一个图像。你的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 } ?>