【发布时间】:2012-03-27 05:04:55
【问题描述】:
我的数据库中有图像链接,例如-http://accessories.us.dell.com/sna/images/products/large/330-5288.jpg 上面的图像链接在我的数据库的一个字段中。我不知道如何使用 php 在我的 html 页面中显示它。任何人都可以帮忙吗? 谢谢
【问题讨论】:
-
4 个答案,没有提到
htmlspecialchars():(
我的数据库中有图像链接,例如-http://accessories.us.dell.com/sna/images/products/large/330-5288.jpg 上面的图像链接在我的数据库的一个字段中。我不知道如何使用 php 在我的 html 页面中显示它。任何人都可以帮忙吗? 谢谢
【问题讨论】:
htmlspecialchars() :(
您是否已经从数据库中获取了 URL?如果是,就输出吧
<?php
# code that fetches data from DB goes here...
?>
<img src="<?php echo $url; ?>" />
【讨论】:
从数据库中选择图像的链接。现在设置您从数据库中选择的图像 src = 值。
<img src="<?php echo $url; ?>" />
干杯...!!!
【讨论】:
<?php
$sql = "SELECT your_image FROM your_table WHERE your_conditions_here";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
?>
<img src="<?php echo $row['your_image']; ?>" />
<?php
}
?>
【讨论】:
选择url,这取决于你的sql语句,所以如果你有很多url,制作变量数组然后存储url然后输出它。但在我的例子中,我假设你只有一个 url,然后我把它放在变量 $url 上,这样你就可以显示它了
<?php
$query = "SELECT * FROM tbl_name";
$result = myqsl_query($query);
while($row = mysql_fetch_assoc($result)){
$url = $row['url']
}
?>
<img src="<?php echo $url; ?>" />
【讨论】: