gpt4 book ai didi

javascript - 问 : PHP Multiple Modal in a button of while loop

转载 作者:行者123 更新时间:2023-12-02 15:16:33 24 4
gpt4 key购买 nike

大家好,有人可以帮助我吗?我在 while 循环中执行了多个按钮。我想在每个按钮中查看单独的模式。

这是我的按钮:

<a href="#myModalRemarks" class="remarksBtn" data-toggle="modal"><i class="fa fa-info-circle fa-lg"></i></a>

我的按钮位于 while 循环内,因为我想获取一个备注数据,并且我想在我的模态中查看这些多个获取的数据。

<?php
include('connection.php');

$sql1 = "SELECT remarks FROM tbl_encode_transmittal WHERE receiver_id = '".$_SESSION['userid']."'";

$rs1 = mysql_query($sql) or die(mysql_error());

while($row1 = mysql_fetch_array($rs1)){?>
<!-- Modal -->
<div class="modal fade" id="myModalRemarks" role="dialog">
<div class="modal-dialog">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Remarks</h4>
</div>
<div class="modal-body">
<?php echo $row1['remarks']; ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
<?php } ?>
</div>
</div>

在我的代码的模态 id 中,我想添加这样的数字 <div class="modal fade" id="myModalRemarks1" role="dialog">每次我获取多个数据时,模态也会有一个增量编号,以便它会设置不同的 id。

最佳答案

我强烈建议你看看这个question并遵循更好方法的答案,就您原来的方法而言是有问题的

模态按钮(位于循环内)添加行 ID receiver_id到模态按钮href="#myModalRemarks<?php echo $row1['receiver_id'];?>"

<a href="#myModalRemarks<?php echo $row1['receiver_id'];?>" class="remarksBtn" data-toggle="modal"><i class="fa fa-info-circle fa-lg"></i></a>

模态 HTML(也在循环内)添加行 id receiver_id模态选择器 id id="myModalRemarks<?php echo $row1['receiver_id'];?>"

<div class="modal fade" id="myModalRemarks<?php echo $row1['receiver_id'];?>" role="dialog">
<div class="modal-dialog">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Remarks</h4>
</div>
<div class="modal-body">
<?php echo $row1['remarks']; ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

模态也将有唯一的 ID

关于javascript - 问 : PHP Multiple Modal in a button of while loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34427769/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com