简体   繁体   English

编辑html表行并使用php将其更新为mysql表

[英]Edit html table row and update It into mysql table using php

I have created update button on my every row in table dynamically using JQuery that successfully editing the table but i don't know how to call php function for updating the database, 我已经使用JQuery动态地在表的每一行上创建了更新按钮,该按钮成功地编辑了表,但是我不知道如何调用php函数来更新数据库,

i have used juery as 我用陪审团作为

$(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);
    }
});

questions: how to pass row id to jquery and then update.php page, i am waighting for your help, i hav google it many times but not able to solve my problem 问题:如何将行ID传递给jquery,然后进行update.php页面,我正竭力为您提供帮助,我曾多次在Google上使用它,但无法解决我的问题

I will prefer to set id of row on edit button as an attribute, and when you click on edit, you can pick id by this element. 我将更喜欢将“编辑”按钮上的行ID设置为属性,当您单击“编辑”时,可以通过此元素选择ID。 Check below code for example: 请检查以下代码,例如:

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

and you can get id on editbtn class click as below: 您可以在editbtn类上单击获取ID,如下所示:

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

And to save updated values, you need to call ajax or need to submit form. 为了保存更新的值,您需要调用ajax或提交表单。 You need to pass all data including row id, other fields value in ajax request. 您需要传递所有数据,包括行ID,ajax请求中的其他字段值。 I will prefer to use Ajax as it will not load your page and it will look much better for UI. 我将更喜欢使用Ajax,因为它不会加载您的页面,并且对于UI而言看起来要好得多。

Hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM