【问题标题】:How to view images from database on to the website document?如何从数据库中查看图像到网站文档?
【发布时间】:2022-02-04 04:39:16
【问题描述】:

我正在尝试显示存储在数据库中的图片,但是当我运行代码时,会出现图片文本的早午餐。 (如下图所示)

这是我显示数据库内容的代码

<?php
include ("connectdb.php");
try {
  $rows = $db -> query("SELECT animal_id, title, animal_dob, animal_type, animal_description,picture_of_animal FROM animals");
    ?> <table>
  <tr>
   <th> Animal id <th> Title </th> <th> Date of birth </th> <th> Type </th><th>Description</th><th>Picture</th>
 </tr> <?php
  foreach ($rows as $rows => $r) {
    ?>
<tr>
 <td><?php echo $r['animal_id']; ?></td>
  <td><?php echo $r['title']; ?> </td>
  <td><?php echo $r['animal_dob']; ?> </td>
  <td><?php echo $r['animal_description']; ?> </td>
  <td><img src "<?php echo $r['picture_of_animal']; ?>" </td>
</tr>
<?php
}
?>

</table>;
<?php
}catch (PDOException $ex) {
  ?>
  <p>Sorry, a database error occurred.</p>
  <p> Error details: <em> <?= $ex->getMessage() ?> </em></p>
<?php
}
?>

这是我的数据表的图片

【问题讨论】:

  • 您不能只回显原始 BLOB,您必须提供仅提供该一张图片的专用 URL(带有正确的标题),或者 inline base64 encode 它。

标签: php html mysql database


【解决方案1】:

你错过了等号所以添加它和alao图像关闭标签

  <td><img src= "<?php echo $r['picture_of_animal']; ?>"/> </td>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    相关资源
    最近更新 更多