我有一个表,在其中我为多个输入分配唯一值,(例如):
<td><?= $PMComments ?><input name="PMComments[]" type="text" value="<?= $PMComments ?>"></td>
从SQL数据库引入的表中的每一行都会收到一个唯一的编号-PMComments1、PMComments2等。由于某些原因,这与我的更新按钮不起作用:
<td><input name="update[]" type="submit" id="update" value="Update"></td>
为什么?
for ($n = 0, $t = count($_POST['PMComments']); $n < $t; $n++) {
$UpdateValue = $_POST['Update'][$n];
$PMCommentsValue = $_POST['PMComments'][$n];
$LineID = $_POST['LineID'][$n];
echo "UpdateValue of $UpdateValue " . "with comments $PMCommentsValue " . " with LineID " . $LineID . "<br>";
}
我收到的回声
UpdateValue of with comments TEST with LineID 11414
我不能为按钮或其他东西指定唯一值吗?
如果您准备使用一些jquery。我会这么做:
- 制作一个通用的可点击按钮或字体图标,并为该按钮指定唯一的id
- 单击该按钮后,从相关输入中获取数据
- 执行ajax post调用以发布表单
- 考虑在ui上闪烁一些东西来标记保存已完成,如
它可以像这样工作(通用语法)
<td><input id='PMComments1' value='...'></td>
<td><button class='submitit' id='submit1' data-id='PMComments1'><i class='fa fa-save'></i></button></td>
...
<td><input id='PMCommentsN' value='...'></td>
<td><button class='submitit' id='submitN' data-id='PMCommentsN'><i class='fa fa-save'></i></button></td>
<script>
$('table').on('click', '.submitit', function() {
var id = $(this).attr('data-id');
var val = $('#'+id).val();
$.post("/my/ajax/handler.php", { id: id, val: val }, function () {
// do ui update tweak here like dim the save button until the next time
});
});
</script>