【问题标题】:How to retrieve and display images from MySQL?如何从 MySQL 中检索和显示图像?
【发布时间】:2017-09-28 17:02:35
【问题描述】:

我只想从 SQL 数据库中检索显示图像,但我不能。

<?php

$sql = "SELECT * FROM two_upload_pics";
$myData = mysql_query($sql);

while($record = mysql_fetch_assoc($myData))
{
    $img=$record["upload_image"];
    print_r($img)
    ?>

    <img src ="uploads/<?php echo $img; ?> style="height: 200px;" class="img-resposive">
    <?php
} 

?>

【问题讨论】:

  • 图片是否在uploads/目录下?
  • 使用 MySQLi 或 PDO 扩展。参考 - code.tutsplus.com/tutorials/…mysql 扩展名已被弃用。
  • 在 src 属性中缺少结尾 "
  • 只是为了澄清一下,您使用的是哪个 RDBSM?是 SQLServer 还是 MySQL?
  • 关于的代码缺少连接调用,因此无法正常工作。你用的是什么版本的 PHP?

标签: php mysql file file-upload


【解决方案1】:

我刚刚修改了您的代码。试试这个。也许它会起作用。

<?php
$sql = "SELECT * FROM two_upload_pics";
$myData = mysql_query($sql);

while($record = mysql_fetch_assoc($myData))
{
    $img=$record["upload_image"];

    echo "<img src ='uploads/$img' style='height: 200px;' class='img-resposive' >";
}
?>

不过,我不建议使用mysql 扩展名。使用PDO or MySQLi

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 2011-12-09
    相关资源
    最近更新 更多