如何显示存储在数据库中的路径的图像? [英] How to Displaying an image with path stored in Database?

查看:96
本文介绍了如何显示存储在数据库中的路径的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 http://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='http://localhost/cms/1/". $image_query_fetch['images'] .'" alt=\"\" />";

*Use PHP *

<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>

这篇关于如何显示存储在数据库中的路径的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆