我在数据库和项目文件夹中存储了图像路径。现在我正试图在我的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); $ b if(!$ query = mysql_query(select product_id,name from products)){ echo mysql_error(); $ b $ else 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']); 回声< / a>; echo& lt; img src =。 $ image_query_fetch ['images']。alt = \\/& gt;; echo'< / pre>'; } else { echo你需要登录才能访问此页面;
解决方案源之前的本地图片路径 $ b 示例
echo< img src ='http:// localhost / cms / 1 /。 $ image_query_fetch ['images']。'alt = \\/>;* 使用PHP *
<?php echohttp://。 $ _SERVER ['HTTP_HOST']。 $ _SERVER [ REQUEST_URI]; ?>
I have stored images path in database and images in project folder. Now i am trying to view all IMAGES with their PRODUCTS in my HTML template. I have written the following code and its given me an empty images box in the output and when i open that image box in the new tab, it opens the following URL.
localhost/cms/1Kindly tell me the way of referring images in 'img src ' tag.
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"; }解决方案
Add your local image path before source
example
echo "<img src='localhost/cms/1/". $image_query_fetch['images'] .'" alt=\"\" />";*Use PHP *
<?php echo "" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>
更多推荐
如何显示存储在数据库中的路径的图像?
发布评论