I have 2 tables. In the first there is a list of products and in the last column I did calculate a total multiplying the values present in 2 cells of the same table (using the following code written in the hook). I indicate below the code used in After Insert and in After Update:
Code: Select all
function Elementi_after_insert($data, $memberInfo, &$args){
$ESKgTot=sqlValue("SELECT `KgTot` FROM `Elementi` WHERE `id`=".$data['id']);
$ESCostoProduzione=sqlValue("SELECT `CostoProduzione` FROM `Elementi` WHERE `id`=".$data['id']);
$ESCostozincatura=sqlValue("SELECT `Costozincatura` FROM `Elementi` WHERE `id`=".$data['id']);
$ESSupplementoverniciatura=sqlValue("SELECT `Supplementoverniciatura` FROM `Elementi` WHERE `id`=".$data['id']);
$ESSupplementotriplex=sqlValue("SELECT `Supplementotriplex` FROM `Elementi` WHERE `id`=".$data['id']);
$ESsomma=$ESCostoProduzione+$ESCostozincatura+$ESSupplementoverniciatura+$ESSupplementotriplex;
$ESCostoTotale=$ESKgTot*$ESsomma;
sql("UPDATE `Elementi` SET `CostoTotale`='".$ESCostoTotale."' WHERE `id`=".$data['selectedID'],$eo);
return TRUE;
Code: Select all
function Elementi_Strutture_after_insert($data, $memberInfo, &$args){
$ESSpessore=sqlValue("SELECT `Spessore` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESPesokgmt=sqlValue("SELECT `Pesokgmt` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESPesokgCad=sqlValue("SELECT `PesokgCad` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESNumero=sqlValue("SELECT `Numero` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESMt=sqlValue("SELECT `Mt` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESCostoMt=sqlValue("SELECT `CostoMt` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESKgTot=sqlValue("SELECT `KgTot` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESCostoProduzione=sqlValue("SELECT `CostoProduzione` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESCostozincatura=sqlValue("SELECT `Costozincatura` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESSupplementoverniciatura=sqlValue("SELECT `Supplementoverniciatura` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESSupplementotriplex=sqlValue("SELECT `Supplementotriplex` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESCostoTotale=sqlValue("SELECT `CostoTotale` FROM `Elementi` WHERE `id`=".$data['Codice']);
$ESTotelementi=sqlValue("SELECT `Quantita_elementi` FROM `Elementi_Strutture` WHERE `id`=".$data['id']);
$rr=$ESKgTot*$ESTotelementi;
sql("UPDATE `Elementi_Strutture` SET `Spessore`='".$ESSpessore."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `Pesokgmt`='".$ESPesokgmt."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `PesokgCad`='".$ESPesokgCad."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `Numero`='".$ESNumero."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `Mt`='".$ESMt."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `CostoMt`='".$ESCostoMt."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `KgTot`='".$ESKgTot."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `CostoProduzione`='".$ESCostoProduzione."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `Costozincatura`='".$ESCostozincatura."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `Supplementoverniciatura`='".$ESSupplementoverniciatura."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `Supplementotriplex`='".$ESSupplementotriplex."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `CostoTotale`='".$ESCostoTotale."' WHERE `id`=".$data['selectedID'],$eo);
sql("UPDATE `Elementi_Strutture` SET `Peso_elementi`='".$rr."' WHERE `id`=".$data['selectedID'],$eo);
$ESPeso_elementi=sqlValue("SELECT `Peso_elementi` FROM `Elementi_Strutture` WHERE `id`=".$data['id']);
$ESCostototelementi=$ESTotelementi*$ESCostoTotale;
sql("UPDATE `Elementi_Strutture` SET `Costototelementi`='".$ESCostototelementi."' WHERE `id`=".$data['selectedID'],$eo);
Now if I update a value in the first table how can I do so that the second table is updated without having to enter each row and click Update?
I can't solve.
Thank you.
Greetings