图像未加载到轮播中
Posted
技术标签:
【中文标题】图像未加载到轮播中【英文标题】:images not loading inside the carousel 【发布时间】:2014-12-29 11:48:49 【问题描述】:我的网站上有一个轮播,并希望从数据库加载图像,虽然轮播工作正常,但图像没有加载
数据库视图
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);
?>
如果有人可以帮助我编写代码将不胜感激
【问题讨论】:
你能告诉我们“carousel_image”的表结构和一些示例数据吗 print_r($row) 得到什么?或者你得到什么样的错误?你最终在你的内联 css 中得到了什么?并且,在设置 CSS 高度和宽度之前,您是否正确地为 background-image:url() 关闭括号? 【参考方案1】:你的问题可能不是 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>';
【讨论】:
以上是关于图像未加载到轮播中的主要内容,如果未能解决你的问题,请参考以下文章