Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php mySQL如何显示图像,img src上的问题_Php_Html_Mysql_Image - Fatal编程技术网

php mySQL如何显示图像,img src上的问题

php mySQL如何显示图像,img src上的问题,php,html,mysql,image,Php,Html,Mysql,Image,我已经做了四个小时了,我仍然没有任何线索,所以我来这里寻求帮助。我正在学习PHP和mySQL,我学习的方式之一就是从开源项目中学习。今天我试图理解一个开源项目,我遇到了一些问题。这里是开源项目的链接:基本上,它有如下内容,我们称之为profileinfo.php(这个文件的名称很有欺骗性,它是一个显示不同用户上传的图像的页面) imageview.php如下所示: <?php $conn = mysql_connect("localhost", "root", ""); mysql_se

我已经做了四个小时了,我仍然没有任何线索,所以我来这里寻求帮助。我正在学习PHP和mySQL,我学习的方式之一就是从开源项目中学习。今天我试图理解一个开源项目,我遇到了一些问题。这里是开源项目的链接:基本上,它有如下内容,我们称之为
profileinfo.php
(这个文件的名称很有欺骗性,它是一个显示不同用户上传的图像的页面)

imageview.php
如下所示:

<?php

$conn = mysql_connect("localhost", "root", "");
mysql_select_db("printstagram") or die(mysql_error());
if(isset($_GET['pid'])) {
    $sql = "SELECT image FROM photo WHERE pid=" . $_GET['pid'];
    $result = mysql_query("$sql") or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysql_error());
    $row = mysql_fetch_array($result);
    header("content-type: image/jpeg");
    echo $row["image"];
}
mysql_close($conn);
?>

当然,如果用户必须点击一个按钮才能看到每个图像,这是非常不方便的。因此,我决定给自己一些练习,修改代码(这是Apache许可证,我可以这样做),这样图像将自动显示在
profileinfo.php
上,而无需单击按钮。由于
imageview.php
listsingleREV.php
显示图像,我尝试用这两个文件替换
profileinfo.php
中的表单。我为此工作了四个小时,没有达到我的目标。有人能告诉我在
profileinfo.php
上显示图像的正确方法而不需要点击按钮吗

正如在imageview.pho中显示的那样,$row[pid]包含照片表中图像的链接,因此将这一行添加到您希望它显示的while循环下的profileinfo.php中
As it appears in imageview.pho the $row[pid] contain the link of your image in photo table so add this line to profileinfo.php under the while loop in the place you want it to display 
 <img src="<?php echo". $row["pid"]."; ?>">
">
imageview.php?pid=
。?HTTP GET参数有一个问号。值得注意的是,这个代码库可能不是最好的学习工具。它使用的API已经从PHP7中删除,因为它太可怕了(
mysql.*
)如果你把它作为一个公共网站,它可能会在几秒钟内被摧毁。看看更多关于做什么和避免什么的最新建议。@tadman我正要评论同样的事情……如果你不理解问号,这意味着你需要先研究HTML协议和它学习php或任何其他web语言。无论如何,你尝试学习是件好事,但这可能是你可能选择的最糟糕的例子。如果你想寻找更好的例子,请看看社区支持的各种例子,而不仅仅是某个人做的一次性周末黑客项目。作为一个例子MPE是一个非常适合初学者的环境,它有很好的文档记录,并向您展示了如何正确组织MVC应用程序。while循环之前的SQL语句应该是什么?profileinfo.php同时调用imageview.php和listsingleREV.php,它们有不同的SQL语句。
<?php

$conn = mysql_connect("localhost", "root", "");
mysql_select_db("printstagram") or die(mysql_error());
if(isset($_GET['pid'])) {
    $sql = "SELECT image FROM photo WHERE pid=" . $_GET['pid'];
    $result = mysql_query("$sql") or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysql_error());
    $row = mysql_fetch_array($result);
    header("content-type: image/jpeg");
    echo $row["image"];
}
mysql_close($conn);
?>
As it appears in imageview.pho the $row[pid] contain the link of your image in photo table so add this line to profileinfo.php under the while loop in the place you want it to display 
 <img src="<?php echo". $row["pid"]."; ?>">