henry henry - 3 months ago 25
PHP Question

How to pass GET value to bootstrap modal

i have a bootstrap modal and am trying to pass a unique value through GET to the modal but the modal keeps getting the same unique value instead of the value of the table row i clicked. Been struggling with this for days and cant seem to figure out why it's not working. The code is below

$sql = "SELECT * FROM houses";
while ($row = mysqli_fetch_array($q)) {
<td><?php echo $row['nickname']; ?></td>
<td><?php echo $row['state']; ?></td>
<td><?php echo $row['city']; ?></td>
<td><?php echo $row['address']; ?></td>
<div class="btn-group">
<a class="btn btn-success" href="view_property.php?house=<?php echo $row['nickname']; ?>"><i class="icon_check_alt2"></i></a>
<a class="btn btn-primary" href="edit_property.php?house=<?php echo $row['nickname']; ?>"><i class="icon_plus_alt2"></i></a>
<a class="btn btn-danger" data-toggle="modal" data-target="#myDelete"><i class="icon_close_alt2"></i></a>
<div id="myDelete" class="modal fade" 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">Delete Property</h4>
<div class="modal-body">
<p>Are you sure you want to pull out this property from your list of Properties, as all data regarding this property will be lost permanently <?php echo $row['nickname']; ?></p>
<div class="modal-footer">
<a class="btn btn-success" href="view_property.php?house=<?php echo $row['nickname']; ?>">Delete</a>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>


HTML ids should be unique, you're using the same id for every iteration.

Try using:

id="myDelete<?php echo $row['id'] ?>"
data-target="#myDelete<?php echo $row['id'] ?>"

Hope this helps!