如果图像显示代码中出现任何问题,请检查以下代码并帮我解决 无标题文档
<body>
<p>how to display image</p>
<p>image is not seeingd</p>
<?php
$con= mysql_connect("localhost","root","");
$d= mysql_select_db("matrimonial",$con);
$id=$_REQUEST['id'];
$sql = "select * from advertiesment where S_NO ='1'" or die(mysql_error());
$result = mysql_query($sql,$con);
if($rows=mysql_fetch_assoc($result))
{
$image = $rows['filepath'];
echo "<img style='width:150px;height:150px' src='$image'>";
echo "<br>";
}
?><p>how to display image</p>
</body>
</html>
答案 0 :(得分:0)
if($rows=mysql_fetch_assoc($result))
情况很糟糕。如果您有更多来自SQL查询的结果,则需要使用while
。
while ($rows = mysql_fetch_assoc($result)) {...
如果您只有一个,请仅删除if
:
$rows = mysql_fetch_assoc($result);
echo ...
修改强>
$image = $rows['filepath'] . '/' . $rows['filename'];
答案 1 :(得分:0)
不要使用:
if($rows=mysql_fetch_assoc($result))
{
$image = $rows['filepath'];
echo "<img style='width:150px;height:150px' src='$image'>";
echo "<br>";
}
直接使用
$行= mysql_fetch_assoc($结果)
$image = $rows['filepath'];
echo "<img style='width:150px;height:150px' src='$image'>";
echo "<br>";