doujie9882 2013-03-31 22:45
浏览 25
已采纳

图像作为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)

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>
";
  • 写回答

2条回答 默认 最新

  • douyin9987 2013-03-31 23:09
    关注

    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 Query

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大