douwen7905 2018-02-16 16:41
浏览 95

从数据库中检索图像但没有显示

I have a form and with this form I submit image to database(I am 100% sure that this form works well and images store properly in database) but when I try to retrieve and show them nothing happens.

<!-- index.php -->
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="fa/font-awesome-4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/bootstrap/bottons/bootstrap.css">
    <link rel="stylesheet" href="css/index.css">
    <title> index.php </title>
</head>
<body>
    <div class="product-row">
        <?php include('showimages.php'); ?>
    </div>
</body>
</html>


---------showimages.php :----------------       
<?php
    $db = mysqli_connect('localhost', 'root', '', 'online_shopping');
    $last_id = mysqli_insert_id($db);
    $query = "SELECT * FROM products ORDER BY productID desc limit 8;"  ;   
    $result = mysqli_query($db, $query);
    header("Content-type: image/jpg");
    while($row = mysqli_fetch_assoc($result)) {             
        echo "<div class='each-product'>
            <div class='product-image' style='background-image: url(".$row['pric1'].")'>
            </div>                 
            <i class='fa fa-heart-o' aria-hidden='true'></i>
            <div class='name'>".  $row['name'] ." </div>
            <div class='price'>" .$row['price'].  "<span class='toman'> dollar </span> </div>
            <div class='add-to-basket'>
                <button type='button' class='btn btn-lg btn-success'> <i class='fa fa-shopping-basket' aria-hidden='true'></i>  add to basket </button>
            </div>
        </div> " ;

    }
?>
  • 写回答

1条回答 默认 最新

  • duanmeng3126 2018-02-16 19:13
    关注

    I do some tweak and this is true answer :

    <div class='product-image' style='background-image: url(data:image/jpeg;base64,".base64_encode($row['pric1'])."')'>
    </div>
    

    (there is no need for header("Content-type: image/jpg");)

    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路