我的数据库中有许多图像,它们都对应于相同的项目 ID。
我希望它们在浏览器中彼此相邻显示。
但以下代码仅输出最新图像,而不是全部:
//get all the images in this project and add them to the content variable for output
if (!empty($FormProjectID)) {
$DBQuery3 = mysqli_query($dblink, "SELECT * FROM images WHERE project_id = '$FormProjectID'");
if (mysqli_num_rows($DBQuery3) < 1) {
$content = '
<p>This project is empty. <a href="index.php?page=upload&id='.$FormProjectID.'">Upload</a> some files to get started.</p>
';
} else {
while($row = mysqli_fetch_array($DBQuery3)) {
$DBImageID = $row['image_id'];
$DBProjectID = $row['project_id'];
$DBImageName = $row['image_name'];
$DBImageDescription = $row['image_description'];
$DBDateCreated = $row['date_created'];
$DBLinkToFile = $row['link_to_file'];
$DBGivenName = $row['given_name'];
//if the image was given a name by the user, display it
//otherwise display the generated name
if (strlen($DBGivenName) > 1) {
$FileName = $DBGivenName;
} else {
$FileName = $DBImageName;
}
$content = '
<div class="image">
<a href="index.php?page=image&id='.$DBImageID.'"><img src="'.$DBLinkToFile.'" alt="'.$FileName.'" title="'.$FileName.'"/></a>
</div>
';
}
}
如何获取所有图像,以便最终 html 看起来像这样:
<div class="image">
<a href="index.php?page=image&id='.$DBImageID.'"><img src="'.$DBLinkToFile.'" alt="'.$FileName.'" title="'.$FileName.'"/></a>
</div>
<div class="image">
<a href="index.php?page=image&id='.$DBImageID.'"><img src="'.$DBLinkToFile.'" alt="'.$FileName.'" title="'.$FileName.'"/></a>
</div>
<div class="image">
<a href="index.php?page=image&id='.$DBImageID.'"><img src="'.$DBLinkToFile.'" alt="'.$FileName.'" title="'.$FileName.'"/></a>
</div>
稍后在我的 html 页面中,我有:
<?php echo $content; ?>