Get data on the remove row to perform added action
Get data on the remove row to perform added action
I have a editor datatable with a REMOVE button.
When I highlight the row and click REMOVE, I would like to update another table with the 'quantity' of the row being deleted but not sure how to get it because I receive an error "Notice: Undefined index: data".
The row I am removing has a quantity that I want to log to another table, so I need to get the "itemid" from the row being deleted so I can query the current table and get the quantity. I'm using $_POST['data']['table_productitems']['itemid'].
Here is my code in the PHP editor file:
$sql = "SELECT quantity FROM table_productitems WHERE itemid = ".$_POST['data']['table_productitems']['itemid'];
$result= $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$addStockCount = $row["quantity"];
}
}
$db->insert( 'table_productstock', [ 'productid' => $thisproduct, 'productname' => $thisproductname, 'insertdate' => date('Y-m-d H:i:s'), 'userid' => $_SESSION['userid'], 'customerid' => $_SESSION['w2'], 'stockcount' => $addStockCount ] );
This question has accepted answers - jump to:
Answers
The
preRemove
event from the PHP libraries is the way to do this. It will give you the data for the row, and execute once per row being removed, and only when rows are being removed.Allan
Thanks Allan
That will work. Just a question...how far back in version numbers does preRemove and postRemove work?
One more question, how is the data accessed from "values"?
For instance, for "json_encode( $values )" how would I access the quantity value?
{"lotnumber":"123456","expirydate":"2008-11-28","quantity":"12"}
It's ok, I am doing the following and it's working:
Editor 1.5.0 was the version that introduced server-side events.
preRemove
was in that version, although it was only made cancellable in 1.6 or 1.7 I think.Allan