简体   繁体   English

我想从phpMyAdmin数据库检索图像并将其显示在HTML表格上

[英]I'd like to retrieve images from phpMyAdmin database and display them on an HTML table

The images are stored as a BLOB type in my database. 图像以BLOB类型存储在我的数据库中。 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. 我希望用户能够单击“查看库存”按钮,并转到带有HTML表的页面,该表显示每个项目的图像。

This is the table in my php file: 这是我的php文件中的表格:

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>";

If your image is stored as blob, you can't do echo "<td><img src='Downloads/".$row['apparelImage']."'></td>"; 如果您的图像存储为Blob,则不能echo "<td><img src='Downloads/".$row['apparelImage']."'></td>";

You should print a img tag which will handling your image. 您应该打印一个img标签,它将处理您的图像。 Pass row ID in src attribute of this tag and get it in script. 在此标签的src属性中传递行ID,并在脚本中获取它。 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: script_to_show_image.php ,从数据库获取记录后,必须设置标题才能正确打印图像:

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

Then, print the content: 然后,打印内容:

echo $apparelImage;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 MySQL 数据库中检索图像并显示在 html 标记中 - How to retrieve images from MySQL database and display in an html tag php代码从mysql数据库中检索数据并显示在html表中 - php code to retrieve data from mysql database and display in html table 我想显示从数据库检索的图像以及文本 - I want to display images as well as text that retrieve from database 如何显示/检索数据库中的所有图像 - How to display/ retrieve all images from the database 如何从数据库中检索和显示图像? - How to retrieve and display images from the database? 我有一个表格可以输入用户详细信息并将其添加到数据库中,还可以检索这些详细信息并将其显示在表格中 - I have a form to input user details to and add them to a database and also retrieve those details and display it in a table 我需要从本地文件夹中检索所有图像(无论编号和名称如何)并将其显示在我的网站上 - I need to retrieve ALL images (regardless of number and name) from a local folder and display them on my website 如何从MySQL数据库中检索BLOB格式的图像并以html格式显示 <img> 标签? - How to retrieve images in BLOB format from MySQL database and display in an html <img> tag? 显示来自phpMyadmin数据库的图像 - displaying images from phpMyadmin database 如何从数据库检索数据并将其显示在表中 - How to retrieve data from database and display it in table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM