我试图通过php显示图像。我在'imglink'下的表格中有tsored图像的文件路径,但是我无法用echo显示它。 你能给我一些关于如何做到这一点的建议吗?我的代码如下。 此外,当我正在测试文件路径时,它需要是完整的路径C:.....等或者它可以只是与图像的文件夹? 谢谢
$sql = "SELECT `Name`, `Location`, `Description`, `Airport`, `imglink` FROM `attractions` WHERE `Category`='HistV'";
$result = mysql_query($sql, $link);
if (!$result)
{
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_assoc($result))
{
echo $row['Name'];
echo "<img src=\"{$row['image']}\" />";
}
答案 0 :(得分:1)
您使用&#39; image&#39;在结果行中,但在您的查询中,它是&#39; imglink&#39;。
echo "<img src='" . $row['imglink'] . "'>";
只要该行实际上具有正确的路径,就应该工作。 检查路径是否正确 - 只需将其打印出来即可。 该路径应该与您调用它的页面相对。
答案 1 :(得分:0)
如果您的'图像'以name.jpg格式存储,那么您所追求的是:
echo '<img src="'.$row['image'].'">';
希望有所帮助!