首先,我已经知道在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'] ?>"/>
代码显示没有错误,但foto_profil
没有显示出来。它只显示一个中断图像图标。正确的代码怎么样?请解释一下你的答案。感谢
答案 0 :(得分:2)
你在这里混合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'] . '"/>';
}