Page 1 of 1

Update DB

Posted: 2020-11-05 08:01
by jgregor
Hello, I am trying to finish a small application: I would like to improve a form where there are several decimal fields, I would like to calculate a field with the values of the other fields. I tried to insert this into events before update $ data ['Celkom'] = $data ['Hmotbody'] + $data ['Srstbody']; with success. In addition I would like to update the field another table with the value of field : Celkom . Could someone help me for the sintaxe. Or is this not the right place to achieve the desired result.Thank you

Re: Update DB

Posted: 2020-11-05 15:05
by onoehring
Hi,

can't you do it like (code not tested) the code below?

Code to be placed in the after update function in /hooks/tabelename.php

Code: Select all

  $sql = "UPDATE yourtablename SET yourfieldname = " . $data['Celkom'] . " WHERE yourPrimaryKeyFieldinTable = " . $selected_ID . ";";
  $yourresult = sqlValue($sql);
Olaf

Re: Update DB

Posted: 2020-11-06 21:05
by jgregor
Hello onoehring and thank you very much for your help, I didn't manage to get your code to work but you helped me with the syntax. I finally found a less elegant form than yours which works for the moment. I also reconfigured my database so that the IDs match. You know, I am not a programmer I do a few small programs from time to time for our breeders association and in the meantime I forget the exact syntax a little. Thank you again.

function olkralikov_after_update ($ data, $ memberInfo, & $ args) {
$ id = makeSafe ($ data [id]);
$ sqlx = sqlValue ("Select Celkom from Olkralikov WHERE Olkralikov.id = $ id");
sql ("UPDATE Zviera SET Ocenenie = '$ sqlx' WHERE Zviera.id = $ id");
return TRUE;