Auto Field Calculation

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
communitywarehouse
Posts: 1
Joined: 2015-07-06 15:03

Auto Field Calculation

Post by communitywarehouse » 2015-07-06 15:15

Hi. I've recently purchased AppGini for our Charity and would like some help understanding how to ADD several FIELDs together in order to show the total in a separate FIELD.

Example:

FIELD4 = FIELD1 + FIELD2 + FIELD3

I'm using version 5.41. I'm not an expert so any help would be appreciated.

The dml files reads like this..

$data['FIELD4] = makeSafe($_POST['FIELD4']);
if($data['FIELD4'] == empty_lookup_value){ $data['FIELD4'] = ''; }

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: Auto Field Calculation

Post by peebee » 2015-07-07 05:03

It's all done in the table specific files in "hooks" folder. http://bigprof.com/appgini/help/advance ... ific-hooks

Hook files are not overwritten if you need to regenerate your Appgini application (say if you upgrade the version or add another field/table). That way, no need to edit any generated Appgini files and your hook files will still work.

See specific example code to add before updating the record here: http://bigprof.com/appgini/help/advance ... ore_update

In your case:

Code: Select all

function tablename_before_update(&$data, $memberInfo, &$args){
	
	// calculate total of field 1 + field 2 + field3
	$data['field4'] = $data['field1'] + $data['field2'] + $data['field3']);
	
	return TRUE;
}
or depending on your circumstances, you might need to apply the code to the before_insert, after_insert or after_update hook function. Read the hooks examples for explanations. Here's your arithmetic operators: http://php.net/language.operators.arithmetic

Post Reply