php - 编辑 html 表行并使用 php 将其更新到 mysql 表中

标签 php jquery mysql

我已经使用 JQuery 动态地在表中的每一行创建了更新按钮,成功编辑了表,但我不知道如何调用 php 函数来更新数据库,

我使用陪审团作为

$(document).ready(function () {
      $('.editbtn').click(function() {
    var $this = $(this);
    var tds = $this.closest('tr').find('td').filter(function() {
        return $(this).find('.editbtn').length === 0;
    });
    if ($this.html() === 'Edit') {
        $this.html('Save');
        tds.prop('contenteditable', true);

    } else {
        $this.html('Edit');
        tds.prop('contenteditable', false);
    }
});

问题: 如何将行id传递给jquery然后update.php页面, 我正在等待你的帮助,我已经谷歌了很多次但无法解决我的问题

最佳答案

我更喜欢将编辑按钮上的行的 id 设置为属性,当您单击编辑时,您可以通过此元素选择 id。检查下面的代码例如:

//Here 1 is id of row which you want to edit
<button class="editbtn" data-id="1">Edit Row</button>

您可以在 editbtn 类上单击获取 id,如下所示:

$('.editbtn').click(function() {
    let rowId = $(this).data("id");
});

并且要保存更新的值,需要调用ajax或者需要提交表单。您需要在ajax请求中传递所有数据,包括行id、其他字段值。我更喜欢使用 Ajax,因为它不会加载您的页面,而且 UI 看起来会更好。

希望对您有帮助。

关于php - 编辑 html 表行并使用 php 将其更新到 mysql 表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54615833/

相关文章:

javascript - 同名元素jquery的索引

php - 上传图片时调整图片大小

javascript - window.resize 事件在 Internet Explorer 中触发

php while循环内存使用情况

php - 删除 php 中的特定行时遇到问题

apache2 - 对等方重置 Apache PHP5-FPM 连接

php - mysql自动将字符串转换为整数

javascript - Knockout js隐藏图片div

javascript - 重置按钮并启动倒数计时器

mysql - 部分搜索mysql字段中的破折号值