Sum of specific values based on yes/no element

madpato

Member
Hello

I am trying to sum specific values based on some yes/no elements but i am struggling with the specific code for my calc element.
Its quite simple: if element A (all are yes/no elements) has a yes sum 30, if element B has yes sum 30, if element C has yes sum 15. Then show the result. Thats all.
Can you help me with the code to achieve this?

Thanks.
 
Last edited:
What code do you have now? What is a "yes sum", and how do you get it to be 15 or 30 from a yes/no element?
 
Hello

I dont have a specific code yet but was thinking of something like:

Code:
$sum = (int) 0;
if (
'{element_a_raw}' = 1;
$sum = 30;
if '{element_b_raw}' =1;
$sum = $sum + 30;
if '{element_c_raw]' =1;
$sum = $sum + 15;
)

return $sum;

Assuming the value of a "yes" of a yes/no element is 1 so if its 1 add 30.
Tried this but gave me an error.

Thanks.
 
Thanks, i am aware is php code but i am not a developer thats why i was asking for a small example with the correct sintaxis so i can move forward. I think it should be:

Code:
if ('{element_a_raw}' == 1);
$sum = 30;
if ('{element_b_raw}' == 1)
$sum = $sum + 30;
if ('{element_c_raw}' == 1)
$sum = $sum + 15;

return $sum;

Thanks again for your time.
 
Hello!
This code you sent needs some adjustments to work the way you need. See below:

$sum = 0;
if ('{element_a_raw}' == 1)

$sum += 30;
if ('{element_b_raw}' == 1)
$sum += 30;
if ('{element_c_raw}' == 1)
$sum += 15;

return $sum;



Hope this helps.
 
Hello thanks for your reply.

If i try that i get syntax error, unexpected token "if"

will keep trying, thanks.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top