[英]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.