图像未加载到旋转木马内

时间:2014-12-29 11:48:50

标签: php mysql sql mysqli carousel

我的网站上有旋转木马,希望从数据库加载图片,虽然旋转木马工作正常,但图片没有加载

数据库视图

    id    image1                   image2               image3
    1  carouselimage/image1  carouselimage/image1   carouselimage/image1

此表中只有一行

轮播代码

 <?php
        require 'connection.php';
            echo "<header id='myCarousel' class='carousel slide'>";
                echo "<ol class='carousel-indicators'>";
                    echo "<li data-target='#myCarousel' data-slide-to='0' class='active'></li>";
                    echo "<li data-target='#myCarousel' data-slide-to='1'></li>";
                    echo "<li data-target='#myCarousel' data-slide-to='2'></li>";
                echo "</ol>";

                echo "<div class='carousel-inner'>";

                    $sql = "SELECT * FROM carousel_image ";

                    $result = mysqli_query($con, $sql);
                    if (mysqli_num_rows($result) > 0) 
                        {
                            while($row = mysqli_fetch_array($result)) 
                                {
                                    $image1=$row['image1'];
                                    $image2=$row['image2'];
                                    $image3=$row['image3'];

                                    echo "<div class='item active'>";
                                        echo "<div class='fill' style='background-image:url('http://example.com/carouselimage/" .$image1."\' height=\'500\' width=\'2000\'/);></div>";
                                    echo "</div>";

                                    echo "<div class='item'>";
                                        echo "<div class='fill' style='background-image:url('http://example.com/carouselimage/" .$image2."\' height=\'500\' width=\'2000\'/);></div>";
                                    echo "</div>";

                                    echo "<div class='item'>";
                                        echo "<div class='fill' style='background-image:url('http://example.com/carouselimage/" .$image3."\' height=\'500\' width=\'2000\'/);></div>";
                                    echo "</div>";
                                }
                        }
                echo "</div>";  

                echo "<a class='left carousel-control' href='#myCarousel' data-slide='prev'>";
                    echo "<span class='icon-prev'></span>";
                echo "</a>";
                echo "<a class='right carousel-control' href='#myCarousel' data-slide='next'>";
                    echo "<span class='icon-next'></span>";
                echo "</a>";
            echo "</header>";

            mysqli_close($con); 
    ?>
如果有人可以帮我处理代码,

会很感激

1 个答案:

答案 0 :(得分:2)

你的问题可能不是SQL,而是这行PHP / HTML和CSS:

echo "<div class='fill' style='background-image:url('http://example.com/carouselimage/" .$image1."\' height=\'500\' width=\'2000\'/);></div>";
                              ^ a ' opens style and ^ this ' closes style again

所以你必须修改你的报价,以及:

echo "<div style='[..]height=\'500\' width=\'2000\'/);></div>";
           ^^^^^^^^^^^^^^^^^ height/width within style="" shouldn't have = or a quote

老实说,这是基本的HTML / CSS,因此我建议您查看 w3schools 以了解如何防止这些错误。它应该是这样的:

echo '<div class="fill" style="background-image:url(http://example.com/carouselimage/' . $image1 . ');height:500px;width:2000px;"></div>';