0

我有这个 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 ;

显示图像的问题。为什么我不能显示我的图像?

4

4 回答 4

0

为什么你用 php 标签关闭?> 当你需要每个 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>";
            } 
于 2013-08-12T11:44:48.727 回答
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']; ?>" />

代码不完整,但你应该明白了。

于 2013-08-12T11:46:27.767 回答
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>"; 
于 2013-08-12T11:40:54.030 回答
0

相关代码是这样的:

echo"<td>";?><img src='image/".$test['picture']."' height="100" width="100" /> <?php echo "</td>"; 

这不是您在 HTML 中插入图像的方式。相反,您需要:

  1. 编写一个检索图像正文的脚本
  2. src属性中链接此类脚本
于 2013-08-12T11:44:26.493 回答