我希望图像显示在一个表内。目前,我在执行文件时收到此消息:解析错误:语法错误,意外的T_ENCAPSED_AND_WHITESPACE,期望T_STRING或T_VARIABLE或T_NUM_STRING,如果有人能为我指出正确的方向,我将非常感谢。
<tr><td>
<?php
$conn = mysql_connect("...", "...", "...");
mysql_select_db ("...");
$query = ("select * from photos where ID = 3");
$result = mysql_query($query) or die(mysql_error()." ".$query);
while($row = mysql_fetch_array($result))
{
echo "<p>$row[title]</p></ br></ br>";
echo "<img src=' . $row['content'] . ' height='200' width='200'/>";
}
mysql_close($conn);
?>
</td></tr>发布于 2012-03-30 22:19:41
看起来你的问题在这一行,因为你混合了单引号和双引号:
echo "<img src=' . $row['content'] . ' height='200' width='200'/>";
你可以像这样重写它:echo "<img src='$row[content]' height='200' width='200'/>";
或者像这样:echo "<img src='" . $row[content] . "' height='200' width='200'/>";
发布于 2012-03-30 22:18:06
您是将图像作为BLOB类型存储在数据库中,还是存储在文件系统中并引用数据库中pic文件的位置?
假设你正在显示图片的本地文件路径,它可能是这样的:
<tr><td>
<?php
$conn = mysql_connect("...", "...", "...");
mysql_select_db ("...");
$query = ("select * from photos where ID = 3");
$result = mysql_query($query) or die(mysql_error()." ".$query);
$path = "path/to/the/pic/";
while($row = mysql_fetch_array($result))
{
echo "<p>$row[title]</p></ br></ br>";
echo "<img src='".$path.$row['content']."' height='200' width='200'/>";
}
mysql_close($conn);
?>
</td></tr>很难从你的问题中真正知道你想要的是什么,你能给我们展示一下DB结构吗……
发布于 2012-03-30 22:19:03
echo "<img src=\"path/to/the/image/" . $row['content'] . "\" height=\"200\" width=\"200\"/>"; https://stackoverflow.com/questions/9944642
复制相似问题