首页 > 解决方案 > 无法显示逗号分隔字符串中的图像

问题描述

我正在尝试显示数据库中的图像但无法显示。请帮我。在此处输入图像描述

我的代码

$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'> ";

}

标签: php

解决方案


您需要遍历$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'> ";

推荐阅读