doushi2902 2011-04-24 10:28
浏览 43
已采纳

我从数据库中提取的图像有时不会在浏览器中显示,但如果我查看源代码,它们就会显示

I've started developing a site that pulls two images randomly from a database.

I assign a random number to a variable, between 1 and the amount of images there are stored in my database. I then query the database looking for that ID, and show the image in HTML image tags. This works fine and the two images appear randomly and I have checking to make sure they are never the same. But sometimes, one or both of the images won't appear on the page but if I view the source code, they are appearing there.

( I should note that the images aren't actually stored WITHIN the database, just the names of them are )

Here is the code that I am using to withdraw them from the database

function selectImage($id)
{
    $query = "SELECT * FROM Images WHERE id = $id";
    $result = mysql_query($query) or die (mysql_error());

    while($row = mysql_fetch_array($result) {
        $image = $row['image'];
        echo "<img src='" . $image . "' />";
    }
}

Anyone know why this only displays the image sometimes? I'm refreshing to make it display another set of images.

  • 写回答

1条回答 默认 最新

  • doutun1875 2011-04-24 10:40
    关注

    Sometimes it can be tricky to sync up the filesystem with the database: If you are able to view the src in the HTML, and the image doesn't appear, then chances are the image doesn't exist, the name is stored incorrectly in your database, or perhaps the extension is being saved incorrectly (storing .jpg but the file is .jpeg or .JPG).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?