Skip to main content
Topic: Action after delete (Read 3865 times) previous topic - next topic

Action after delete

classic 2.6.7 “Action after delete” does not work using “rec_id”. Example I want to update a number in another table other than the one I am deleting when deleting a record and the idea is to make a subtraction through an INNER JOIN but it does not do it if I remove the “rec_id” makes the subtraction but to all the values ​​of the other table ... the point is that the "action after add" works perfect when adding a record. I hope it is understood if I will not pass project and base.

Re: Action after delete

Reply #1
@alfre91‍ there is no bug there, just tested it with mine and it works perfectly. your MySQL query to perform that action might be wrong, the best way to be sure about that is to test your MySQL query with MySQL triggers. or the alternative is to create a sample so that I can set the correct Mysql statement for you. More about MySQL trigger

Thanks.

Re: Action after delete

Reply #2

I will be doing these days ...
Thank you

Re: Action after delete

Reply #3
Here I leave a brief explanation and the basis and the project
https://drive.google.com/open?id=14JTTfkEY3aqxERs90GyJgHOC1O7stRhi
https://drive.google.com/open?id=1Gvus4HWA4Q4eILSDXwvEtfDR41Ud3E91
https://drive.google.com/open?id=11OvUq4ZByxMeN5DcSAt24QyIL4ny3dAL
https://drive.google.com/open?id=15_Q29Bq8_MDvBIal-1N8Ou5WJFleDJVU
basis and the project
https://drive.google.com/open?id=17vVCw32z_y0gubI4Hlj4enkfRW2w1Lvc


the idea is to guide me in how I have to put in "action after delete" or "action before delete"



THANK YOU

Re: Action after delete

Reply #4
@alfre91‍ please add this
Code: [Select]
$db->rawQuery("UPDATE prueba SET data_list=data_list - 1 WHERE id='$modeldata['id_data']'");
to your "data" table Delete Page, Action After Delete and let me know if it works fine on yours.
why the record id($rec_id) does not work for you is because the record being deleted does not have its id reference on the prueba table, rather prueba table has its id referenced in the data table as  id_data.
thanks.

Re: Action after delete

Reply #5
Hello Goodnight. Thank you very much for the quick response. It didn't work out. genius, thank you anyway, I hope you can.

Re: Action after delete

Reply #6
@alfre91‍ I noticed that the error from the previous query was because of no data in the $modeldata['id_data'] being used in the query. the new solution would be to add this 👇
Code: [Select]
$db->where('id',$rec_ids);
$prueba_id = $db->getValue('data', 'id_data');
to your Action Before Delete and add this 👇
Code: [Select]
$sql = "UPDATE prueba SET prueba.data_list = (prueba.data_list - 1) WHERE id = ".$prueba_id;
$db->rawQuery($sql);
to your Action After Delete. I hope this resolves your issue.

Attached the .ppm file below in case you encounter any issue.


 

Re: Action after delete

Reply #7

This is perfect, great. a pleasure. The best is true. thank you

Re: Action after delete

Reply #8
I return to the same topic, I would like to delete a record from the "prueba" table, delete the record from the "data" table taking into account that, "prueba.id" and the "data.id_data" are the same. Is it possible to do it from action after delete from the "prueba" table?.
what would I have to put?. thank you very much geniuses

Re: Action after delete

Reply #9
@alfre91‍ the following code should do the trick.
Code: [Select]
$db->rawQueryOne("DELETE from tablename WHERE id IN ($rec_ids)");
 
Where tablename is the table you want to delete records from and id is the column that links the record to the current data that was deleted before executing the above delete query.

Re: Action after delete

Reply #10

You're a genius.

Re: Action after delete

Reply #11
@alfre91‍ I noticed that the error from the previous query was because of no data in the $modeldata['id_data'] being used in the query. the new solution would be to add this 👇
Code: [Select]
$db->where('id',$rec_ids);
$prueba_id = $db->getValue('data', 'id_data');
to your Action Before Delete and add this 👇
Code: [Select]
$sql = "UPDATE prueba SET prueba.data_list = (prueba.data_list - 1) WHERE id = ".$prueba_id;
$db->rawQuery($sql);
to your Action After Delete. I hope this resolves your issue.

Attached the .ppm file below in case you encounter any issue.



i've the same problem, i can't update after delete
below is my test project, simple inventory. using PHPRad Classic 2.7.1 Trial,
i hope someone can help me. thank you

Re: Action after delete

Reply #12
@alfre91‍ I noticed that the error from the previous query was because of no data in the $modeldata['id_data'] being used in the query. the new solution would be to add this 👇
Code: [Select]
$db->where('id',$rec_ids);
$prueba_id = $db->getValue('data', 'id_data');
to your Action Before Delete and add this 👇
Code: [Select]
$sql = "UPDATE prueba SET prueba.data_list = (prueba.data_list - 1) WHERE id = ".$prueba_id;
$db->rawQuery($sql);
to your Action After Delete. I hope this resolves your issue.

Attached the .ppm file below in case you encounter any issue.



i've the same problem, i can't update after delete
below is my test project, simple inventory. using PHPRad Classic 2.7.1 Trial,
i hope someone can help me. thank you

finally found newbee error,
this is what i do:
purchases>>Delete Page>> Action Before Delete:
Code: [Select]
$db->where('id',$rec_id);
$products_id = $db->getValue('purchases', 'product_id');

purchases>>Delete Page>>Action After Delete:
Code: [Select]
//$count_qty = $db->rawQuery("SELECT SUM(received_number) FROM purchases WHERE product_id=$products_id");

//execute SQL statement and return the result
//$params    = array($products_id);
//$count_qty = $db->rawQuery("SELECT SUM(received_number) FROM purchases WHERE product_id=$products_id", $params);

$sql = "UPDATE products SET products.received_inventory = (SELECT SUM(received_number) FROM purchases WHERE product_id=$products_id) WHERE id = $products_id ";
$db->rawQuery($sql);

 i originally want to use $count_qty instead a nested query, but it was fail to me.
please suggest with better sql query.

thank you

Re: Action after delete

Reply #13
@heri.pmck‍ this is your query, written using the phprad query functions.

purchases>>Delete Page>>Action After Delete:
Code: [Select]
$db->where('product_id',$products_id);
$sum = $db->getValue('purchases', 'SUM(received_number)');

$sql = "UPDATE products SET products.received_inventory = ? WHERE id = ?";
$db->rawQuery($sql, array($sum, $products_id));



Re: Action after delete

Reply #14
@willvin thank you so much, run perfecto  8)