PHP和MySQL:从数据库中获取图像
发布于 2021-04-20 23:08:58
我上传了多张图片,并且所有图片的路径都已存储在一起。
使用explode
我已经将它们分开,现在我希望在轮播中回显它们
我正在使用的代码是:
<?php
$con=mysqli_connect("localhost","root","","db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$idd = $_GET['id'];
echo "<header id='myCarousel' class='carousel slide'>";
/* Indicators */
echo"<ol class='carousel-indicators'>";
echo"<li data-target='#myCarousel' data-slide-to='0' ></li>";
echo"<li data-target='#myCarousel' data-slide-to='1'></li>";
echo"<li data-target='#myCarousel' data-slide-to='2'></li>";
echo"</ol>";
$sql = "SELECT * FROM register_office WHERE id='".$idd."'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0)
{
/* Wrapper for slides*/
echo"<div class='carousel-inner'>";
echo"<div class='item'>";
while($row = mysqli_fetch_assoc($result))
{
$str= $row["offimage"];
$array = explode('*', $str);
foreach ($array as $item)
{
echo "<div class='fill'>";
echo "<img src=\"http://example.com/abc/" . $item . "\" height=\"500\" width=\"2000\"/>";
echo "</div>";
}
echo"</div>";
echo"</div>";
}
/*Controls*/
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>";
?>
但它只显示一张图像。另外,当我使用next控件时,即使我尝试向前或向后移动,此控件也不会显示任何图像。
关注者
0
被浏览
127
1 个回答