Search code examples
javascriptphpmysqljsontabulator

How to retrieve only the updated rows data from the tabulator as a JSON object?


I am working with Tabulator which has an Input Field in it through which the user can enter a numeric value, and I need to upload the data from it as it is to MySQL Database. However, I want a way to get only the updated rows i.e. only the rows in which the user has entered value so that I can just update those rows in MySQL Database. I wish to get only the updated row data as a JSON Object so that I can just pass it to my PHP code through the AJAX Request.


Solution

  • Ok let me answer your question. While you are updating a row then definitely you have used a unique id to update the row. After update you should use that same unique id and fetch the data from database from that same row which you have updated. And at last put it in echo with json encode that will be the response of you ajax request see my code it will work for sure:-

     // update the row where unique id is quote_id
    
          $sqlbt = "UPDATE `quote_data_master_kotak` SET `reg_date` = '$reg_date', 
                    `make_year` = '$makeyear' WHERE `quote_id` = '$quoteid'";
          $result = $conn->query($sqlbt); //row updated
    
        //now its time to get the updated row data using quote_id as unique id
    
        $sql = "SELECT * FROM `quote_data_master_kotak` WHERE `quote_id` = '$quote_id'";
        $result = $conn->query($sql);
        if ($result->num_rows > 0) {
                $updated_row_data = $result->fetch_assoc();
                $data['row_data'] = $updated_row_data ;
        }
    
        //now you can echo it in Json formate
             echo json_encode($data);
    
       // output json like this:-
    
           {
            "row_data":{
    
               "quote_id":"5",
               "reg_date":"20/11/2018",
               "make_year":"2018"
                    }
           }