简体   繁体   English

无法显示逗号分隔字符串中的图像

[英]Unable to display images from a comma separated string

I'm trying to display images from database but unable to show.我正在尝试显示数据库中的图像但无法显示。 Please help me.请帮我。 在此处输入图像描述

My code我的代码

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

}

You need to loop over the values in $documents["image"] .您需要遍历$documents["image"]中的值。 Try this:尝试这个:

$images = explode(',', $documents["image"]);
foreach ($images as $image) {
    echo "<img src='uploads/".$documents["reg_id"]."/$image' width='800' height='500'> ";
}

or if you only want do display one of them eg the first, something like this:或者,如果您只想显示其中一个,例如第一个,则如下所示:

$images = explode(',', $documents["image"]);
echo "<img src='uploads/".$documents["reg_id"]."/".$images[0]."' width='800' height='500'> ";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM