不使用php在div内动态检索数据库字段

时间:2015-11-05 09:23:49

标签: php html

<div id="thumbnail-slider" >
    <div class="inner" style="height:500px;">
        <?php
        $query = "select * from released_movies";
        $queryr = $con->query($query);
        while ($row = $queryr->fetch_assoc()) {
            ?> 
            <ul>
                <li>
                    <a href="single.php"><img src="../AbaamAdmin/Released_Movies/<?php echo $row['rel_movies_pics']; ?>" width="900" height="500" class="thumb"> </a>
                </li>
            </ul>

        <?php } ?>

    </div> <!-- .inner-->
</div> <!-- .thumbnail-slider-->

查询只检索1张图片,而不是数据库中给出的完整图片。但是,如果我删除div,查询执行正常。提前谢谢。

2 个答案:

答案 0 :(得分:1)

试试这个

<div id="thumbnail-slider">
    <div class="inner" style="height:500px;">
        <?php
        $query="select * from released_movies";
        $queryr=$con->query($query);
        ?>
        <ul>
            <?php           
            while($row=$queryr->fetch_assoc())
            {
                ?>          
                <li>
                    <a href="single.php">
                        <img src="../AbaamAdmin/Released_Movies/<?php echo $row['rel_movies_pics'];?>" width="900" height="500" class="thumb"> 
                    </a>
                </li>
            <?php 
            }
            ?>
        </ul>
    </div> <!-- .inner-->
</div> <!-- .thumbnail-slider

答案 1 :(得分:0)

您在while循环中开始和结束<ul>

哪个不正确,你应该在while循环之前启动它,如果在while循环之后结束。

更正后的代码:

<?php
$query = "select * from released_movies";
$queryr = $con->query ( $query );
?>
<ul>
<?php
while ( $row = $queryr->fetch_assoc () ) {
?>
    <li><a href="single.php">
    <img src="../AbaamAdmin/Released_Movies/<?php echo $row['rel_movies_pics'];?>"
            width="900" height="500" class="thumb"> </a></li>
<?php }?>
</ul>