Edit html table row and update It into mysql table using php

10
February 11, 2019, at 2:30 PM

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

Answer 1

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.

READ ALSO
Get count posts of model Post Laravel

Get count posts of model Post Laravel

I have a model Post, in this model I created accesor:

27
How can i use dropdown in table &lt;td&gt; tag

How can i use dropdown in table <td> tag

I have an Inline editable Table which updates the Mysql table for the team group column I want to use the drop-down list

35
Devilbox laravel register page throws 502 but works after refresh

Devilbox laravel register page throws 502 but works after refresh

I have setup laravel on devilbox and I'm creating my first application using this tutorial: https://auth0com/blog/creating-your-first-laravel-app-and-adding-authentication/

28