图片作为MySQL数据库中的链接? [英] Images as links in MySQL database?
本文介绍了图片作为MySQL数据库中的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将图像链接存储到数据库中,然后将它们回显到页面上。...这可能吗,我该怎么做? (回显实际图像,而不是图像链接)
I want to store image links into a database and then echo them onto a page.... Is this possible and how do I do it? (echo the actuall images and not the image link)
您可以看到我的代码回显了:$ link,$ description和$ title。我想添加另一个回显 $ imagelink的元素。
As you can see my code echo's out: The $link, $description and $title. I want to add another element which echos $imagelink.
echo "
<div class=\"pagination\" style=\"display:inline\"><ul style=\"background-color:#\"><li><div class=\"span3_search\"><h2><a href='$link'><b>$title</b></a></h2><br><img id=\"result_img\" src=\"img/lvmo.png\" /><br />
$description<br />
<a href='$link'>$link<br /><br /></a><p></div></li></ul></div>
";
推荐答案
简短答案
在 src
属性中仅将 echo
移出图像的URL,就会显示该图像
Short answer
Simply echo
out the URL of the image in the src
attribute and the image will be displayed.
<img id="result_img" src="<?php echo $imagelink; ?>" />
有效解决方案:
表设计:
Worked Solution:
Table Design:
images
| id | title | link | imagelink | description |
------------------------------------------------------------------------
| 1 | Some Title | http://www.google.com | myimage1.png | Some text |
------------------------------------------------------------------------
| 2 | My Title | http://www.yahoo.com | myimage2.png | Some text |
SQL查询
SELECT title, link, imagelink, description FROM images WHERE id = ?
PHP
<?php
$stmt = $mysqli->prepare("SELECT title, link, imagelink, description FROM images WHERE ID = ?");
$stmt->bind_param("i", $ID);
$stmt->execute();
$stmt->bind_result($title,$link,$imagelink,$description);
$stmt->fetch();
?>
<div class="pagination" style="display:inline">
<ul style="background-color:#">
<li><div class="span3_search">
<h2><a href='<?php echo $link; ?>'><b><?php echo $title; ?></b></a></h2>
<br />
<img id="result_img" src="<?php echo $link; ?>" />
<br />
<?php echo $description; ?>
<br />
<a href='<?php echo $link; ?>'><?php echo $link; ?><br /><br /></a>
<p></div>
</li>
</ul>
</div>
这篇关于图片作为MySQL数据库中的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文