Form在循环时在php中显示相同的数据
Form is presenting same data in php while loop
我正试图获得一个编辑表单来处理php中的循环。我有一个删除按钮,它工作得很好。编辑表单只显示表中的第一行。在firebug中,它显示所有其他表单都有正确的唯一id,但当在不同的行上单击编辑时,只有第一个表单显示。有人能帮我解释一下为什么吗?
<table id="table_id" class="table table-hover table-striped">
<thead>
<tr>
<th>ID #</th>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_assoc($search_sql)) {
?>
<tr>
<td id = "clicked"><?=$row['ID']?></td>
<td id = "clicked"><?=$row['Product']?></td>
<td id = "clicked"><?=$row['Quantity']?></td>
<td id = "clicked">$ <?=$row['Price']?></td>
<td>
<button class="btn btn-warning btn-sm" onclick="div_show2(this, '<?=$row['ID']?>'); return false;"><span class="glyphicon glyphicon-edit"></span>Edit</button>
<!-- Modal for the Edit Data Form -->
<div id ="hidden-form2">
<div id = "popupContact">
<form action= "updateData.php" id = "editForm<?=$row['ID']?>" method="POST" name="editForm">
<input type="hidden" name="ID" value="<?=$row['ID']?>">
<div class="form-group">
<label for="product">Product</label>
<input type="text" class="form-control" id="product<?=$row['ID']?>" name="product" value="<?=$row['Product']?>">
</div>
<div class="form-group">
<label for="quantity">Quantity</label>
<input type="text" class="form-control" id="quantity<?=$row['ID']?>" name="quantity" value="<?=$row['Quantity']?>">
</div>
<div class="form-group">
<label for="price">Price</label>
<input type="text" class="form-control" id="price<?=$row['ID']?>" name="price" value="<?=$row['Price']?>">
</div>
<button type="button" class="btn btn-default" onclick="formHide2()">Close</button>
<button type="submit" id="save" class="btn btn-primary">Save changes</button>
</form>
</div>
</div>
<!--End of Edit Form-->
</td>
<td>
<!--Delete Button Form-->
<form method="post" action="deleteData.php">
<button class="btn btn-danger btn-sm" type="submit"><span class="glyphicon glyphicon-trash"></span>Delete</button>
<input type="hidden" id="ID" name="ID" value="<?=$row['ID']?>">
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
//将编辑表单调用为模式弹出窗口的脚本//显示编辑表单弹出菜单的功能
function div_show2() {
document.getElementById("editForm").reset();
document.getElementById('hidden-form2').style.display = "block";
}
//Function to Hide Popup
function formHide2(){
document.getElementById('hidden-form2').style.display = "none";
}
show_div2
函数只显示一个元素。
document.getElementById('hidden-form2').style.display = "block";
这说明了你为什么只看到第一排。
按照以下更新HTML和Javascript
HTML
<div id="hidden-form2<?=$row['ID']?>">
Javascript
function div_show2(id) {
document.getElementById("editForm"+id).reset();
document.getElementById('hidden-form2'+id).style.display = "block";
}
为了避免将来出现任何类似的问题,请始终确保您的id是唯一的。
我看到的前4个td
都使用相同的id
名称clicked
。试着先解决这个问题,看看会发生什么。
<td class="clicked" id="clickedID<?=$row['ID']?>"><?=$row['ID']?></td>
<td class="clicked" id="clickedProduct<?=$row['ID']?>"><?=$row['Product']?></td>
<td class="clicked" id="clickedQuantity<?=$row['ID']?>"><?=$row['Quantity']?></td>
<td class="clicked" id="clickedPrice<?=$row['ID']?>">$ <?=$row['Price']?></td>
相关文章:
- 如何将json数据显示为html
- 解耦按钮(两个按钮同时切换),并根据数据显示相应的按钮
- 将json提要数据显示为html
- 使用Ajax Get方法将数据显示到特定元素中
- 如何将数据显示为线性highChart
- Json显示来自网站的数据显示仅未定义
- 使 ajax 请求和成功数据显示在 id <选择>选择>部分中
- 在按钮单击时将图像URL数据显示到弹出框中,而无需禁用背景
- 如何在循环中将 json 数据显示为 HTML
- 如何使用javascript在html中将firebase数据显示为列表
- PHP同时循环数组数据显示到javascript中
- 原始图像数据显示
- 如何在 y 轴上将数据显示为 KB、MB、GB、TB
- Ajax 数据显示在包含 10 行的表中
- 如何让 Mathjax.js 与 ANCII.js 将附加的 json 数据显示为正确的公式
- 调用 Worklight 适配器并将列表视图中的 JSON 数据显示为字符串
- Jquery/Javascript Datatables : 如何在行选择时将行数据显示到 html 文本字段中
- 双击 td 时,如何在警告框中将数据库中的数据显示为 html 表
- 日期之间的数据显示所有头
- 如何使用模板中的数据显示谷歌地图