简体   繁体   中英

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,

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

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. 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').click(function() {
    let rowId = $(this).data("id");
});

And to save updated values, you need to call ajax or need to submit form. You need to pass all data including row id, other fields value in ajax request. I will prefer to use Ajax as it will not load your page and it will look much better for UI.

Hope it will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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