当前,我的项目有问题。在MySQL数据库中,有两列名为photo before
和photo_after
的列,其格式为 BLOB 。在将图像显示到PHP页面时,我使用base64
对图像进行解码。
主要问题是,如果列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>
答案 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')