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>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?