【发布时间】:2013-05-19 14:21:06
【问题描述】:
我正在尝试显示来自数据库的图像并且我能够得到它,但问题是,即使我上传了不同的图像,它也显示相同的图像。
这是我的代码:
<?php
$con = mysql_connect('localhost','root','')
or die(mysql_error());
mysql_select_db ("dbname");
$query = "SELECT * FROM news ORDER BY date DESC";
$result = mysql_query($query);
echo "<table align='center'>";
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>";
echo "<img src='getImage.php?id='".$row['id']."' height='230px' width='300px'> <br /><br />";
//Some codes here...
echo "</table>";
mysql_close($con);
?>
getImage.php
<?php
$con = mysql_connect('localhost','root','')
or die(mysql_error());
mysql_select_db ("dbname");
$query = "SELECT * FROM news ORDER BY date DESC";
$result = mysql_query($query);
header("Content-type: image/png");
while($row = mysql_fetch_assoc($result))
{
echo $row['image'];
}
mysql_close($con);
?>
请。帮帮我……
【问题讨论】:
-
Please, don't use
mysql_*functions in new code。它们不再维护and are officially deprecated。看到red box?改为了解prepared statements,并使用PDO 或MySQLi - this article 将帮助您决定哪个。如果你选择 PDO,here is a good tutorial. -
尝试清除浏览器缓存...这将确认这不是客户端问题。 (在大多数现代浏览器中,left shift+refresh 通常会进行未缓存的重新加载)
-
– John Conde 谢谢!
-
– Orangepill 我尝试清除浏览器缓存但还是一样。好像它只是显示最后一个 id...
标签: php database image png blob