2013-07-26 53 views
0

我已将图像路径存储在数据库和项目文件夹中的图像。现在我正试图在我的HTML模板中查看与他们的产品的所有图像。我写了下面的代码,并给出了输出中的空白图像框,当我在新选项卡中打开该图像框时,它会打开以下URL。如何显示存储在数据库中的路径的图像?

http://localhost/cms/1 

请告诉我在'img src'标记中引用图像的方式。

enter image description here

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"; 

} 
+1

mysql_被弃用功能的PHP 5.5的.0,使用mysqli_或PDO。** REF:http://www.php.net/manual/en/function .mysql-fetch-array.php ** – dreamweiver

回答

2

源之前,添加本地图片路径

例如

echo "<img src='http://localhost/cms/1/". $image_query_fetch['images'] .'" alt=\"\" />"; 

* 使用PHP *

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

我会推荐相对URL。 –

+1

如果您计划发布您的HTML,请勿使用localhost。 –

+0

什么是相对URL?我如何在这里使用它们? –

相关问题