我已将数据库中的图像路径和项目文件夹中的图像存储起来。现在我想在我的HTML模板中查看其产品的所有图像。我编写了以下代码,并在输出中给出了一个空图像框,当我在新选项卡中打开该图像框时,它会打开以下URL。
http://localhost/cms/1
请告诉我在'img src'标签中引用图片的方式。
include 'connect.php';
$image_query = "select * from product_images";
$image_query_run = mysql_query($image_query);
$image_query_fetch = mysql_fetch_array($image_query_run);
if (!$query=mysql_query ("select product_id,name from products")) {
echo mysql_error();
} else {
while ($query_array = mysql_fetch_array($query)) {
echo '</br><pre>';
$product_id = $query_array['product_id'];
echo "<a href='single_product.php?product_id=$product_id' >";
print_r ($query_array['name']);
echo "</a>";
echo "<img src=". $image_query_fetch
['images'] ." alt=\"\" />";
echo '</pre>';
}
}
} else {
echo "You need to Log in to visit this Page";
}
答案 0 :(得分:2)
在源
之前添加本地图像路径示例强>
echo "<img src='http://localhost/cms/1/". $image_query_fetch['images'] .'" alt=\"\" />";
* 使用PHP *
<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>
答案 1 :(得分:1)
您可以使用HTML基本标记设置将从中解析相对URL的基本URL。 见 - &gt; http://www.w3schools.com/tags/tag_base.asp