php - 无法显示逗号分隔字符串中的图像
问题描述
我的代码
$id = $_GET['reg_id'];
$sql13 = "select * from contacts where reg_id=" . $id;
$result13 = mysqli_query($conn, $sql13);
if (mysqli_num_rows($result13) > 0) {
while($documents = mysqli_fetch_array($result13))
{ ?>
<li class="make_text1" style="font-size:16px">
<span class="definition"><b>
<?php if(!empty($documents["name"])){ echo
$documents["name"]; }?><br><?php
if(!empty($documents["image"])){
$upload_dir = 'uploads/';
// echo "<img src='uploads/".$documents["image"]."' width='800' height='500'> ";
echo "<img src='uploads/".$documents["reg_id"]."/".$documents["image"]."' width='800' height='500'> ";
}
解决方案
您需要遍历$documents["image"]
. 尝试这个:
$images = explode(',', $documents["image"]);
foreach ($images as $image) {
echo "<img src='uploads/".$documents["reg_id"]."/$image' width='800' height='500'> ";
}
或者,如果您只想显示其中一个,例如第一个,则如下所示:
$images = explode(',', $documents["image"]);
echo "<img src='uploads/".$documents["reg_id"]."/".$images[0]."' width='800' height='500'> ";
推荐阅读
- reactjs - 如何在 useEffect() 中正确实现 setState()?
- java - 如何根据使用 Java 解析的顺序对 HashMap 进行排序?
- c++ - 如何将某个字符与字符串的另一个字符进行比较
- api - 如何向单个 Restful API 应用程序授予对移动和 Web 应用程序的访问权限
- spring - 将大量对象保存到数据库中的性能改进思路
- docker - Docker 卷投资主机到机器
- python - Python同时继承abc.ABC和typing.SupportsBytes
- performance - Fortran 性能,在每个子程序调用时分配或声明一个全局变量并分配一次
- amazon-s3 - VPN 中 AWS Lambda 函数的 s3fs 超时问题
- python-3.x - 在 Pandas 中创建新列时应用 lambda 函数时出错