Modal弹出所有记录相同的信息
Modal pop the same information for all records
我正在使用 foreach 循环循环 DIV。我的 PHP 看起来像这样:
<?php foreach ($record as $row) { //looping the records ?>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<h4><?php echo get_userdetails_byid($row['user_id']); ?></h4>
</div>
</div>
<?php } ?>
并且模式始终显示循环的第一个条目.. 但是在 html 源代码中我可以看到所有记录。我如何单独触发每个结果?
data-target="#myModal"
将使用 id
属性。而且多个element
不能有相同的id
。对不同的 modal
使用不同的 id
。
<?php
$i = 0;
foreach ($record as $row) { //looping the records
?>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal<?php echo $i;?>">
Launch demo modal
</button>
<div class="modal fade" id="myModal<?php echo $i;?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<h4><?php echo get_userdetails_byid($row['user_id']); ?></h4>
</div>
</div>
<?php
$i++;
}
?>
我正在使用 foreach 循环循环 DIV。我的 PHP 看起来像这样:
<?php foreach ($record as $row) { //looping the records ?>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<h4><?php echo get_userdetails_byid($row['user_id']); ?></h4>
</div>
</div>
<?php } ?>
并且模式始终显示循环的第一个条目.. 但是在 html 源代码中我可以看到所有记录。我如何单独触发每个结果?
data-target="#myModal"
将使用 id
属性。而且多个element
不能有相同的id
。对不同的 modal
使用不同的 id
。
<?php
$i = 0;
foreach ($record as $row) { //looping the records
?>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal<?php echo $i;?>">
Launch demo modal
</button>
<div class="modal fade" id="myModal<?php echo $i;?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<h4><?php echo get_userdetails_byid($row['user_id']); ?></h4>
</div>
</div>
<?php
$i++;
}
?>