我正在尝试在新页面上打印特定图像。发生的事情是单击上传的图像,将其带到一个单独的页面,我将使用该页面进一步详细描述该图像。
当我输入图像的特定ID时,将加载该图像。示例:(SELECT * FROM gallery WHERE idGallery = 7 ORDER BY orderGallery DESC“)这将为我发布的所有图像加载ID为7的图像。我希望新页面能够将每个图像与其各自的ID相关联,因此当我进入这个新页面时,它将加载正确的图像。
include_once 'includes/dbh.inc.php';
$sql = "SELECT * FROM gallery ORDER BY orderGallery DESC";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statment failed!";
} else {
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
echo '<a href="detail.php?imageId="'.$row["idGallery"].'>
<div style="background-image:url(images/gallery/'.$row["imgFullNameGallery"].');"></div>
<h3>'.$row["titleGallery"].'</h3>
<h4>'.$row["descGallery"].'</h4>
</a>';
}
}
$sql = "SELECT * FROM gallery WHERE idGallery='".$_GET['idGallery']."'ORDER BY orderGallery DESC";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statment failed!"; }
else {
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
echo '<img src="images/gallery/'.$row["imgFullNameGallery"].'">
<h3>'.$row["titleGallery"].'</h3>
<h4>'.$row["descGallery"].'</h4>
</a>';
}
}
注意:未定义索引:第6行的C:\ xampp \ htdocs \ webpage \ detail.php中的idGallery
这是我收到的错误,因此我假设错误在于我如何定义idGallery,但我无法弄清楚它是如何错误的。我还注意到,当我将鼠标悬停在图像上时弹出的链接没有说图像ID,而是显示“ detail.php?imageId =“,但没有继续使用其余的代码。是什么导致该ID无法显示?