我试着用php从数据库中获取数据,以在html元素中的模型中显示...我使用foreach循环,并进入我从数据库中获取的数据,但它没有改变ID来查看它的数据...它总是显示最后一条记录
我尝试用另一种方法在另一个页面中打开它,它工作...但我想在同一页面中使用它([PHP_SELF]),但我不能这样做
<div class="main-slide">
<div class="gallery">
<?php
foreach($folders as $folder) {
echo '<div class="x-gallery text-center">';
?>
<!-- Start option Span -->
<span >
<a href="#&foldid=<?php echo $folder['Folder_ID']?>">
<!-- Button trigger modal -->
<button type="button" class="btn btn-light" name="editFolder" data-bs-toggle="modal"
data-bs-target="#exampleModalOption">
<i class='fa-solid fa-pen-to-square'></i>
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalOption" tabindex="-1"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Options </h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="container">
<form class="form-horizontal main-form"
action="<?php echo $_SERVER['PHP_SELF'] ; ?>"
method="POST" enctype="multipart/form-data">
<!-- ID Input Hidden -->
<input type="hidden" name="foldid"
value="<?php echo $folder['Folder_ID']?>">
<!-- User Name field -->
<div class="mb-3 row col-mid-4">
<label class="col-sm-2 col-form-label">Folder Name</label>
<div class="col-sm-10 col-md-10">
<div class="form-group">
<input
type="text"
name="name"
class="form-control"
value ="<?php echo $folder['Folder_Name'] ?>"
autocomplete="off"
required="required"
/>
</div>
</div>
</div>
<!-- Button -->
<div class="mb-3 row">
<div class="d-grid gap-2 col-8 md-flex justify-content-md-end">
<input type="submit" name="editFolder" value="Save"
class="btn btn-primary " />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</a>
</span>
<!-- End Option Span -->
<?php
echo "<span class=''>".$folder['Folder_Name']."</span>";
if(empty($folder['Folder_Cover'])) {
echo "<a href='#'>
<img class='card-img-top' src='images/no-image.jpg' alt='empty'>
</a> ";
}else {
echo "<a href='#'>
<img class='card-img-top'
src='data/uploads/album-Images/".$folder['Folder_Cover']."' alt=''>
</a> ";
}
echo"</div>";
}
?>
</div>
1条答案
按热度按时间q43xntqr1#
多亏了Marty在评论中的建议,我才得以解决这个问题:
foreach($folders as $key=>$folder)
您可以使用此索引通过添加data-bs-target="#exampleModalOption_<?php echo $key;?>"
来保持ID字段的唯一性,然后添加相同的模态IDid="exampleModalOption_<?php echo $key;?>"