猿问

尽管 MySQL 数据库中有数据,但图像不显示

目前,我的项目有问题。photo before在 MySQL 数据库中,有两个名为photo_afterBLOB的列。base64在将图像显示到 PHP 页面时,我使用它来解码图像。


主要问题是列中是否有数据photo_before或者photo_after它仍然显示' noimage.jpg '。我不知道为什么。下面是我的代码:


<?php

$report_id = $_GET['report_id'];



$sql = "SELECT * FROM report LEFT JOIN users ON report.badgeid = users.badgeid LEFT JOIN team ON team.team_id = users.team_id WHERE report_id = :report_id";

$query = $conn->prepare($sql);

$query->execute(array(':report_id' => $report_id));

while($row = $query->fetch(PDO::FETCH_ASSOC)){


    $report_id = $row["report_id"];

    $report_date = $row["report_date"];

    $task_name = $row["task_name"];

    $photo_before = $row["photo_before"];

    $photo_after = $row["photo_after"];

    $ot_start = $row["ot_start"];

    $ot_end = $row["ot_end"];

    $time_photo_before = $row["time_photo_before"];

    $time_photo_after = $row["time_photo_after"];

    $report_status = $row["report_status"];


}


?>


<tr>

  <td rowspan = '2'><b>Before Task</b></td>


  <?php

    if(!isset($row['photo_before']) || empty($row['photo_before'])) {

        echo "<td colspan='3'><img src='../../images/faces/noimage.png'/></td>";

      }else{ 

              echo "<td colspan='3'><img src='data:image/jpeg;base64,".$row['photo_before']."'/></td>"; 

      }

  ?>


</tr>

<tr>

  <td colspan='3'><?php echo "Time: <b>" .$time_photo_before."</b>"; ?></td>

</tr>

<tr>

  <td rowspan = '2'><b>After Task</b></td>

  <?php

    if(!isset($row['photo_after']) || empty($row['photo_after'])) {

        echo "<td colspan='3'><img src='../../images/faces/noimage.png'/></td>";

      }else{ 

              echo "<td colspan='3'><img src='data:image/jpeg;base64,".$row['photo_after']."'/></td>"; 

      }

  ?>

</tr>


繁星点点滴滴
浏览 262回答 2
2回答

qq_笑_17

empty() 函数返回 true 或 false 当变量数据存在并且具有非空、非零值时,它返回 FALSE。否则返回 TRUE。添加并尝试,希望它会工作:if(!isset($row['photo_after'])&nbsp;||&nbsp;empty($row['photo_after'])==&nbsp;'true/false')

开心每一天1111

似乎问题出在 Your 上if( the problem is here ),||&nbsp;/ 或逻辑发送真如果 0|1,1|0 和 1|1...检查你的 php 版本,".$row['photo_before']."你的 " 使用 " 或 ',我的使用'.$row['photo_before'].'
随时随地看视频慕课网APP
我要回答