Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.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-显示来自数据库的图像_Php_Sql_Image - Fatal编程技术网

PHP-显示来自数据库的图像

PHP-显示来自数据库的图像,php,sql,image,Php,Sql,Image,首先,我已经知道stackoverflow中也有关于php中显示图像的类似问题。但是,我的代码很简单&不像其他代码那样复杂,所以我希望您可以用一种简单的方式回答它 在数据库中,我有mahasiswa表。它有以下字段: nrp | nama | pass | jatah_sks | foto_profil 我希望程序显示foto_profil,这是一个图像。图像保存在文件夹propic中。这是我的代码: $sql4 = "select foto_profil from mahasiswa"

首先,我已经知道stackoverflow中也有关于php中显示图像的类似问题。但是,我的代码很简单&不像其他代码那样复杂,所以我希望您可以用一种简单的方式回答它

在数据库中,我有
mahasiswa
表。它有以下字段:

nrp | nama | pass | jatah_sks | foto_profil

我希望程序显示
foto_profil
,这是一个图像。图像保存在文件夹
propic
中。这是我的代码:

$sql4 = "select foto_profil from mahasiswa"
        . " where nrp=".$nrp;
$result4 = mysqli_query($link, $sql4);
if (!$result4) {
      die("<h3>SQL Error</h3>" . $sql4);
}
$row4 = mysqli_fetch_array($result4);

<img src="propic/<?php echo $row4['foto_profil'] ?>"/>
$sql4=“从mahasiswa选择foto_profil”
. “其中nrp=”.$nrp;
$result4=mysqli_查询($link,$sql4);
如果(!$result4){
死(“SQL错误”。$sql4);
}
$row4=mysqli_fetch_数组($result4);
"/>

代码没有显示任何错误,但不会显示
foto_profil
。它只显示了一个中断图像图标。正确的代码是什么?请解释您的答案。谢谢您在这里混合了php和html。您想要:

$sql4 = "select foto_profil from mahasiswa"
        . " where nrp=".$nrp;
$result4 = mysqli_query($link, $sql4);
if (!$result4) {
      die("<h3>SQL Error</h3>" . $sql4);
}
while ($row4 = mysqli_fetch_array($result4)) {
    echo '<img src="propic/' . $row4['foto_profil'] . '"/>';
}
$sql4=“从mahasiswa选择foto_profil”
“其中nrp=”.$nrp;
$result4=mysqli_查询($link,$sql4);
如果(!$result4){
死(“SQL错误”。$sql4);
}
而($row4=mysqli\u fetch\u数组($result4)){
回声';
}
哦,我没有写“while”这句话。谢谢