我上传了多张图片,并且所有图片的路径都已存储在一起。
使用explode我已经将它们分开,现在我希望在轮播中回显它们
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控件时,即使我尝试向前或向后移动,此控件也不会显示任何图像。
这里可能有一些问题…
1.爆炸()
首先,explode()如果您的$row1["offimage"]字符串*在文件名之间没有星号,则您可能无法工作。在对OP的回复评论中,您给了我们一个示例的内容$row1["offimage"],该示例不会用星号分隔每个PNG文件*:
explode()
$row1["offimage"]
*