-1

我的数据库表表名“商店”

id |  regno |  name  |  image
------------------------------
1  |  101   |  xxxxx |  myimage

在这里,我可以从数据库中搜索特定图像,但我需要以相同的形式显示所有详细信息,例如 regno、名称和图像,请任何人帮助我

表.php

<form action ="table.php" method="post">
search :<input type="text" name="search">
<input type="submit" name="submit">
</form>
<?php

echo $search =$_POST['search'];
 ?>

<table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1     bordercolor="#2696b8">
<tr>
<td align="center" width="45" height="45"><img src="image.php?reg=<?php echo $search?>">


</tr>

</table>

图像.php

<?php
mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("databaseimage") or die(mysql_error());
$sql ="select * from store where reg= '".intval($_GET['reg'])."' ";

$result = mysql_query($sql) or die(mysql_error());
header('Content-Type: image/png');
 echo mysql_result($result, 0);
if($result){
  $row = mysql_fetch_row($result);
  echo $row['image'];



}
else
{
  echo readfile('/your/path/error/image.png');
}?>

在此查询中,我无法显示图像,请帮助我

4

4 回答 4

0

您可以使用显示图像

<img src="upload/<?php echo $row['image']; ?>">

upload 是您上传图片的文件夹名称

于 2013-08-22T08:44:47.187 回答
0

您是否检查过您的查询是否返回任何结果集?
您应该使用数据库表中所述的表字段名称“regno”来匹配 url 查询“reg”

$sql ="select * from store where regno = '".intval($_GET['reg'])."' ";

而不是使用无效字段名称“reg”来构建查询的原始查询

$sql ="select * from store where reg = '".intval($_GET['reg'])."' ";

其次,
您是否尝试在网页上显示图像?
您可以简单地执行以下操作,但请记住您的 $row['image'] 应该包含图像文件的绝对或相对路径。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<img src="<?php echo $row['image']; ?>">
</body>
</html>
于 2013-08-22T08:51:52.500 回答
0
from store where reg= '

你有regno领域,但没有reg

此外,您不需要将标头内容类型设置为图像,因为您的请求返回字符串,而不是实际图像。

于 2013-08-22T08:44:03.053 回答
0

尝试这个

<form action ="<?=$_SERVER['PHP_SELF']?>" method="post">
search :<input type="text" name="search">
<input type="submit" name="submit" name="Search">
</form>
<?php
if(isset($_REQUEST['submit'])){

    $s = $_REQUEST['search'];
    mysql_connect("localhost","root","")or die(mysql_error());
    mysql_select_db("databaseimage") or die(mysql_error());
    $sql ="select * from store where reg= '%".$s."%' ";

    $result = mysql_query($sql) or die(mysql_error());
    $count = mysql_num_rows($result);

    if($count != 0){
        while($row = mysql_fetch_array($result)){
          echo $row['image'].'<br>';
          echo $row['regno'].'<br>';
          echo $row['name'];
        }
    }
    else{
      echo 'Error Message';
    }
}
?>
于 2015-01-07T17:40:09.833 回答