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

时间:2019-12-06 04:23:57

标签: php mysql

当前,我的项目有问题。在MySQL数据库中,有两列名为photo beforephoto_after的列,其格式为 BLOB 。在将图像显示到PHP页面时,我使用base64对图像进行解码。

主要问题是,如果列photo_beforephoto_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>

2 个答案:

答案 0 :(得分:0)

问题似乎出在您的if( the problem is here ),|| /或逻辑如果0 | 1,1 | 0和1 | 1 ...则发送true ...也检查您的php版本,其中".$row['photo_before']."您的“使用”或“,我的使用'.$row['photo_before'].'

答案 1 :(得分:0)

empty()函数返回true或false 当变量数据存在并且具有非空,非零值时,它将返回FALSE。否则返回TRUE。 添加并尝试,希望它能起作用:

if(!isset($row['photo_after']) || empty($row['photo_after'])== 'true/false')