【发布时间】:2018-07-31 02:02:44
【问题描述】:
除了像这样回显它之外,还有其他方法可以将图像从 MySQL 放入 html:
echo "<img src='images/" . $row['event_image'] . "' height='200' width='320' class=responsivez> ";
我试图将图像路径放在 html 标记上。 getImage.php 显示我的图像路径,但在下一页调用时图像不显示。我错过了一些重要的语法吗?
<img src="images/getImage.php?" width="175" height="200" />
getImage.php
<?php
$con=mysqli_connect("localhost","root","","blast");
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
$state='Johor';
$result=mysqli_query($con,"SELECT * from blast_events where
event_state='$state'");
if (!$result) {
die ('SQL Error: ' . mysqli_error($con));
}
else{
}
$row=mysqli_fetch_array($result);
echo $row["event_image"];
?>
【问题讨论】:
-
执行 cmd+u(在 Mac 上)或 ctrl+u(在 Windows 上),并查看
src属性中的链接正确与否。 -
您正在以完全正确的方式进行此操作(除了参数化);回显
<img>标签。话虽如此,$row['event_image']不应该给你getImage.php?。是在你的表格行吗?你应该存储类似image001.png的东西。然后您的<img>标签将正确映射(假设相关图像在服务器上)。 -
@ObsidianAge 是的。 event_image 是数据库上的图像列名称。 getImage.php 显示图像的名称,.png