dougu3591 2014-12-29 11:48
浏览 50
已采纳

图像未加载到旋转木马内

i have a carousel on my website and wish to load images from database, although the carousel is working fine, but the images are not loading

Database View

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

there wouldbe only one row in this table

code for carousel

 <?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); 
    ?>

would appreciate if someone could help me with the code

  • 写回答

1条回答 默认 最新

  • duanjia4220 2014-12-29 12:43
    关注

    Your problem is probably not the SQL, but this line of PHP/HTML and 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
    

    So you gotta fix your quotes, and as well:

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

    Honestly this is basic HTML/CSS, so I would advise you to look at w3schools to learn how to prevent these mistakes. It should be something like this:

    echo '<div class="fill" style="background-image:url(http://example.com/carouselimage/' . $image1 . ');height:500px;width:2000px;"></div>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路