如何使用 php 将图像从 mysql 显示到表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10051976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i display image from mysql to table using php
提问by sanjay
Here is my code-
这是我的代码-
<?php
$con = mysql_connect('db', 'table', 'p/w');
if (!$con) {
die('Could not connect: ' . mysql_error()); }
mysql_select_db("db", $con);
$result = mysql_query("SELECT * FROM computers WHERE KEYWORDS='Computers,Desktops'");
echo "<table border='1' width='100%' >";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['NAME'] . "</td>";
echo "<td>" . $row['MANUFACTURER'] . "</td>";
I want to display image from db stored as path here in one of the columns
我想在其中一列中显示存储为路径的数据库中的图像
echo "</tr>"; }
echo "</table>";
mysql_close($con);
?>
can anyone help? thanks
有人可以帮忙吗?谢谢
回答by sujal
<?php
$con = mysql_connect('db', 'table', 'p/w');
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("db", $con);
$result = mysql_query("SELECT * FROM computers WHERE KEYWORDS='Computers,Desktops'");
echo "<table border='1' width='100%' >";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['NAME'] . "</td>";
echo "<td>" . $row['MANUFACTURER'] . "</td>";
echo "<td><img src='folder_name/".$row['image_name']."'></td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
folder_name=Name of the folder where image is saved
image_name=field name of the image in your table name computers
folder_name= 保存图片的文件夹名称
image_name= 表中图片的字段名称 名称computers
回答by sikas
You can use the img element wherever you want to show the image.
您可以在任何想要显示图像的地方使用 img 元素。
echo "<img src='" . $row['image'] . "'>". You can also check img element for HTMLor img element for HTML5
echo "<img src='" . $row['image'] . "'>". 您还可以检查HTML 的img 元素或HTML5 的 img 元素

