我有这个PHP代码(view.php)
然后我有php代码(mysql_connect.php)
和MySQL
CREATE TABLE IF NOT EXISTS `menu` (
`no` int(100) NOT NULL AUTO_INCREMENT,
`ref` varchar(30) NOT NULL,
`course` text NOT NULL,
`name` text NOT NULL,
`price` int(10) NOT NULL,
`description` text NOT NULL,
`picture` longblob NOT NULL,
PRIMARY KEY (`no`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
显示图像的问题。为什么我无法显示我的形象?
答案 0 :(得分:0)
试试这段代码:
echo"<tr>";
echo"<td>" .$test['ref']."</td>";
echo"<td>" .$test['course']."</td>";
echo"<td>" .$test['name']."</td>";
echo"<td>Rp.".$test['price']."</td>";
echo"<td>" .$test['description']."</td>"; ?>
<td><img src='http://mysite.com/image/<?php echo $test['picture']; ?>' height="100" width="100" /> <?php echo "</td>";
echo"<td> <a href ='edit.php?ref=$id'><center>Edit</a></td>";
echo"<td> <a href ='del.php?ref=$id'><center>Delete</a></td>";
echo"<td></td>";
echo "</tr>";
答案 1 :(得分:0)
相关代码是:
echo"<td>";?><img src='image/".$test['picture']."' height="100" width="100" /> <?php echo "</td>";
这不是您在HTML中插入图片的方式。相反,你需要:
src
属性答案 2 :(得分:0)
为什么你用php标签关闭?&gt;当你需要每个tr的图像时,你需要这样做:
while($test = mysql_fetch_array($result))
{
$id = $test['ref'];
echo"<tr>";
echo"<td>" .$test['ref']."</td>";
echo"<td>" .$test['course']."</td>";
echo"<td>" .$test['name']."</td>";
echo"<td>Rp.".$test['price']."</td>";
echo"<td>" .$test['description']."</td>";
echo"<td><img src='image/".$test['picture']."' height='100' width='100' />";
echo "</td>";
echo"<td> <a href ='edit.php?ref=$id'><center>Edit</a></td>";
echo"<td> <a href ='del.php?ref=$id'><center>Delete</a></td>";
echo"<td></td>";
echo "</tr>";
}
答案 3 :(得分:0)
图片栏是BLOB。这意味着您无法直接在标签中显示它。您需要有一个php脚本,它将在src属性中显示图像并链接到该脚本。
<强> img.php 强>
$no = $_GET['no'];
// fetch the record from the database into $image (be careful at sql injection)
// Check the mime type of the image and add the appropriate header
//header('Content-Type: image/gif');
//header('Content-Type: image/png');
header('Content-Type: image/jpeg');
echo $image['picture'];
然后显示如下图像:
<img src="img.php?no=<?php echo $dbRecord['no']; ?>" />
代码不完整但你应该明白。