截至目前,我可以在单列中显示我的图像,包括图像、标题和简短描述。所有这些都来自同一个数据库。我不太擅长编码,需要一些指导,您如何将现有代码添加到 1) 允许图片显示在多列中……以及 2) 允许单击缩略图,这将加载一个单独的页面,然后我可以在上面设置样式并列出完整的食谱。我一直在搞乱代码,我对我创建的内容感到困惑。我不知道如何继续。<h2>index.php:</h2><section class="gallery-links"> <div class="wrapper"> <div class="gallery-container"> <?php 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="#"> <div style="background-image: url(img/gallery/'.$row["imgFullNameGallery"].');"></div> <h3>'.$row["titleGallery"].'</h3> <p>'.$row["descGallery"].'</p> </a>'; } } ?> </div> <?php echo '<div class="gallery-upload"> <form action="includes/gallery-upload.inc.php" method="post" enctype="multipart/form-data"> <input type="text" name="filename" placeholder="File name..."> <input type="text" name="filetitle" placeholder="Image title..."> <input type="text" name="filedesc" placeholder="Image description..."> <input type="file" name="file"> <button type="submit" name="submit">Upload</button> </form> </div>' ?> </div></section><h2>gallery-upload.inc.php:</h2><?phpif (isset($_POST['submit'])) {$newFileName = $_POST['filename'];if (empty($newFileName)) { $newFileName = "gallery";} else {$newFileName = strtolower(str_replace(" ", "-", $newFileName));}$imageTitle = $_POST['filetitle'];$imageDesc = $_POST['filedesc'];
1 回答
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
基本上,您需要在anchor标签上创建一个链接,该链接将包含url图像详细页面,image id如下所示:
while ($row = mysqli_fetch_assoc($result)) {
// assuming that imgId is your primary key
echo '<a href="detail.php?imageId="'.$row["imgId"].' target="_blank">
<div style="background-image: url(img/gallery/'.$row["imgFullNameGallery"].');"></div>
<h3>'.$row["titleGallery"].'</h3>
<p>'.$row["descGallery"].'</p>
</a>';
}
之后,您需要创建一个新文件detail.php,您可以image id通过该文件进行$_GET['imgId']查询,然后将能够获得完整的图像详细信息。您还需要创建一个HTML视图并可以显示详细信息。
希望对你有帮助!!
- 1 回答
- 0 关注
- 194 浏览
添加回答
举报
0/150
提交
取消