桌子:
<table class="table table-bordered">
<thead>
<tr>
<th>Works At</th>
<th>First Name</th>
<th>Middle Initial</th>
<th>Last Name</th>
<th>Start Date</th>
<th>SSN#</th>
<th>Modify</th>
</tr>
</thead>
<?php
$query = "SELECT * FROM employees";
$stmt = $db->prepare($query);
$stmt->execute();
foreach ($stmt as $row): ?>
<tr>
<td><?php echo $row['rest_id_employees']; ?></td>
<td><?php echo $row['fname']; ?></td>
<td><?php echo $row['minit']; ?></td>
<td><?php echo $row['lname']; ?></td>
<td><?php echo $row['start_date']; ?></td>
<td><?php echo $row['ssn']; ?></td>
<td style="text-align: center">
<div class="btn-toolbar">
<div class="btn-group">
<a class="btn btn-danger" href="<?php echo $_SERVER['PHP_SELF'].'?ssn='.urlencode($row['ssn']); ?>#delModal" data-toggle="modal"><i class="icon-trash icon-white"></i> Delete</a>
<a class="btn btn-warning" href="#editModal"><i class="icon-wrench icon-white"></i> Edit</a>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
</table>
我的目标是将 $row['ssn'] 的值传递给我的#delModal。我认为问题在于:
<a class="btn btn-danger" href="<?php echo $_SERVER['PHP_SELF'].'?ssn='.urlencode($row['ssn']); ?>#delModal" data-toggle="modal"><i class="icon-trash icon-white"></i> Delete</a>
据我了解,使用上述语法,我应该能够$_GET['ssn']
在 Bootstrap Modal 中使用来提取值,但是当我var_dump($ssn)
只NULL
打印值时。
这是模态:
<div class="modal hide" id="delModal" aria-hidden="true">
<div class="modal-header">
<h3 style="color: red">WARNING</h3>
</div>
<div class="modal-body">
<?php
$ssn = $_GET['ssn'];
var_dump($ssn);
?>
<h4>You are about to delete --- from your Employee database.</h4>
<p>An employee cannot be recoverd once they have been deleted. They can be added to the system again, but
all data about the employee will be lost if you delete them. Are you sure you mean to delete this
employee from the database?</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<a class="btn btn-danger" href="deleteemployee.php?ssn=<?php echo urlencode($ssn); ?>"><i class="icon-trash icon-white"></i> Delete</a>
</div>
</div>
此实现的总体目的是使用 Modal 作为一种通过提示用户警告来避免意外删除员工的方法。我不能只$row
在 Modal 中使用,因为它每次都会拉出最后一行,而且我确信有比我在这里尝试做的更好的方法来实现我想要做的事情,但我不是确定那是什么。