drbvm26000 2019-02-26 19:41
浏览 108

我想从phpMyAdmin数据库中检索图像并将它们显示在HTML表格中

The images are stored as a BLOB type in my database. I want the user to be able to click on a 'View Inventory' button and be taken to a page with an HTML table that displays images for each item.

This is the table in my php file:

echo "<table border='1'>";
        echo "<tr>";
            echo "<th>Categor</th>";
            echo "<th>Description</th>";
            echo "<th>Unit Cost</th>";
            echo "<th>XS Quantity</th>";
            echo "<th>S Quantity</th>";
            echo "<th>M Quantity</th>";
            echo "<th>L Quantity</th>";
            echo "<th>XL Quantity</th>";
            echo "<th>XXL Quantity</th>";
            echo "<th>XXXL Quantity</th>";
            echo "<th>Image</th>";
            echo "<th></th>";
        echo "</tr>";
    while($row=mysqli_fetch_array($result)) {
        echo "<tr>";
            echo "<td>{$row['category']}</td>";
            echo "<td>{$row['description']}</td>";
            echo "<td>$ {$row['unitCost']}</td>";
            echo "<td>{$row['xsQuantity']}</td>";
            echo "<td>{$row['sQuantity']}</td>";
            echo "<td>{$row['mQuantity']}</td>";
            echo "<td>{$row['lQuantity']}</td>";
            echo "<td>{$row['xlQuantity']}</td>";
            echo "<td>{$row['xxlQuantity']}</td>";
            echo "<td>{$row['xxxlQuantity']}</td>";
            echo "<td><img src='Downloads/".$row['apparelImage']."'></td>";
            echo "<td><a href='#'>Add</a></td>";
        echo "</tr>";
    }
    echo "</table>";
  • 写回答

1条回答 默认 最新

  • dpqmu84646 2019-02-26 19:57
    关注

    If your image is stored as blob, you can't do echo "<td><img src='Downloads/".$row['apparelImage']."'></td>";

    You should print a img tag which will handling your image. Pass row ID in src attribute of this tag and get it in script. Then, get the record from database and set headers to show image.

    Like:

    echo '<img src="script_to_show_image.php?id=' . $row['id'] . '">';
    

    In script_to_show_image.php, after get record from database, you must set headers to print image correctly:

    header("Content-Type: image/jpeg");
    

    Then, print the content:

    echo $apparelImage;
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP