javascript - 单击img时如何修复当前行的删除?
问题描述
我一直在努力尝试使用模式作为确认从我的数据库中删除特定行。SQL 有效,但仅在没有模式的情况下有效。(模态是必需的)
从较早的搜索中,我尝试并未能实施来自不同问题的提示。
while ($row = $statement ->fetch(PDO::FETCH_ASSOC)) {
Here I create a variable to use later
<?php $username = $row['username']; ?>
<td>
<div class="adjust-buttons">
<input
type="image"
id="delete"
alt="delete"
src="../img/delete.png"
onclick="showModal();"
onmouseover="this.src='../img/delete-hover.png';"
onmouseout="this.src='../img/delete.png';">
<div id="myModal" class="modal">
<div class="modal-content">
<h3>Delete user</h3>
<?php
echo 'are you sure you want ' .$username. ' removed?';
?>
<input
class="modal-button"
type="button"
value="Cancel"
onclick="hideModal();">
<input
class="modal-button"
type="button"
value="I'm sure"
id="<?php echo $row['username']; ?>"
onclick="document.location.href='../delete-user/delete-user.php?username=<?php echo $row['username']?>'" />
</div>
</div>
</div>
</td>
</tr>
<?php } ?>
</table>
我希望删除的行是从循环中选择的行。情况并非如此,无论我按下哪个删除按钮,都只会选择第一个创建的行。
解决方案
while ($row = $statement ->fetch(PDO::FETCH_ASSOC)) {
Here I create a variable to use later
<?php $username = $row['username']; ?>
<td>
<div class="adjust-buttons">
<input
type="image"
id="delete"
alt="delete"
src="../img/delete.png"
onclick="showModal('<?php echo $row['username']; ?>');"
onmouseover="this.src='../img/delete-hover.png';"
onmouseout="this.src='../img/delete.png';">
<div id="myModal<?php echo $row['username']; ?>" class="modal">
<div class="modal-content">
<h3>Delete user</h3>
<?php
echo 'are you sure you want ' .$username. ' removed?';
?>
<input
class="modal-button"
type="button"
value="Cancel"
onclick="hideModal();">
<input
class="modal-button"
type="button"
value="I'm sure"
id="<?php echo $row['username']; ?>"
onclick="document.location.href='../delete-user/delete-user.php?username=<?php echo $row['username']?>'" />
</div>
</div>
</div>
</td>
</tr>
<?php } ?>
和onclick方法
function showModal(modal_id)
{
$('#myModal'+modal_id).show('modal');
}
尝试这个...
推荐阅读
- python - 从 Bitbucket 中删除文件夹
- c# - 为 DTO 使用可空引用类型的最佳实践
- c++ - 当两个 std::map 对象相同时
- sql - DB2 中的 PLSQL 是否支持嵌套的 while 语句?
- c# - Regex.Matches 为正则表达式 c# 抛出异常
- javascript - Vue中双向绑定props的正确方式是什么?
- azure - 如何为 Container Registry Azure 创建只读访问密钥
- python - 按跨年的日历周分组
- mysql - 这个“医疗保健”数据库的 sql 查询代码是什么?
- asp.net - 超时后处理“无法解密防伪令牌”错误