如何显示存储在数据库中的路径的图像?

编程入门 行业动态 更新时间:2024-10-25 18:33:35
本文介绍了如何显示存储在数据库中的路径的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在数据库和项目文件夹中存储了图像路径。现在我正试图在我的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/1

Kindly 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 "&lt;img src=". $image_query_fetch ['images'] ." alt=\"\" /&gt;"; 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']; ?>

更多推荐

如何显示存储在数据库中的路径的图像?

本文发布于:2023-10-07 10:42:34,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   路径   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!