从数据库显示图像到我的页面


Showing Image to my page from database

我创建了一个页面来显示数据库中的表。但问题是图像没有正确显示,而不是给我的图像的链接,例如:(../../images/i1.jpg)是我的代码有问题吗?

<html>
<head>
<title>View Records</title>
</head>
<body>
<?php
include('connect-db.php');
$result = mysql_query("SELECT * FROM products9 ORDER BY id ASC")
or die(mysql_error());
echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>";
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>Product</th> <th>Price</th> <th></th> <th></th></tr>";
while($row = mysql_fetch_array( $result )) {
echo "<tr>";
echo '<td>' . $row['p_name'] . '</td>';
echo '<td>' . $row['image'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
echo "</tr>";
}
echo "</table>";
?>
<p><a href="new.php">Add a new record</a></p>
</body>
</html>
 </div>

use <img src="<?=$row['image']?>" >

你没有使用img标签,只是你把图像URL到td标签解决方案:修改这一行:

echo '<td>' . $row['image'] . '</td>'; 

to this:

echo '<td><img src="' . $row['image'] . '" /></td>';

如果再次出现问题,请检查浏览器中的图像URL,看看图像是否出现!