我正在尝试在网页上显示图像,其中存储在数据库和图像中的图像路径存储在服务器中。但是我无法使用以下代码显示这些图像,所以请有人帮我解决这个问题,..
<form method="post" enctype="multipart/form-data" action="file_upload.php">
<table>
<?php
$dbhost = 'xxxxxxxx';
$dbuser = 'xxxxxxxxx';
$dbpass = 'xxxxxxxxxx';
$db_name = 'xxxxxxxxxx';
$tbl_name = 'xxxxxxxxxxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$db_name")or die("cannot select DB");
$query1 = mysql_query("select * from '$tbl_name' where id='1'");
$rows1 = mysql_fetch_array($query1);
$path1 = $rows1['image'];
$query2 = mysql_query("select * from '$tbl_name' where id='2'");
$rows2 = mysql_fetch_array($query2);
$path2 = $rows2['image'];
$query3 = mysql_query("select * from '$tbl_name' where id='3'");
$rows3 = mysql_fetch_array($query3);
$path3 = $rows3['image'];
echo '<tr><td><img src="$path1"></td>' ;
echo '<td><img src="$path2"></td>' ;
echo '<td><img src="$path3"></td></tr>' ;
?>
</form>
</table>
输出打印$ path1,$ path2和$ path3 only,.. /
答案 0 :(得分:2)
像这样更改您的查询
所有这些
$query1 = mysql_query("select * from ".$tbl_name." where id='1'") or die(mysql_error());
您将$ path变量作为字符串更改传递
喜欢这个
echo "<tr><td><img src='".$path1."'></td>";
答案 1 :(得分:0)
请更正此行:
echo "<tr><td><img src='$path1'></td>" ;
echo "<td><img src='$path2'></td>" ;
echo "<td><img src='$path3'></td></tr>" ;
关于引用:)
答案 2 :(得分:0)
使用 HTML + PHP就像
<tr><td><img src='<?php echo $path;?>'></td>