Conditional summing values from repeating group

Hi! Usually I can manage Fabik quite well, but now I'm totally stuck.

I have a form with two groups: Group A and Group B (repeating). The goal is to sum in calc element of Group A, all iterations of elements from Group B, but ONLY if other element from Group B (dropdown) has a specific value.

Here's what I've done so far: since fetching elements from Group B in real time (AJAX) requires operating on arrays in Group A, I've fetched two needed arrays:

Code:
$debt = $data['money_21_repeat___debt']; //amounts to be summed
$title = $data['money_21_repeat___title_raw']; //dropdown

Now I want to sum in Group A all the $debt values, but only if $title == 'book' in the same iteration. So I merged these two arrays:

Code:
$merged = array_map(null, $title, $debt);

and then walked the $merged array:

Code:
$sumloop = '';
foreach ($merged as $i => $item) {
    if ($merged[$i][0] == 'book') {
        $sumloop += $merged[$i][1];
    }
}
return $sumloop;

...and it goes sounth. If I comment out the 'if' condition, it works like a charm - whenever I change any value in any repeating group, $sumloop gets immediately updated. But when I put the condifion again, the value of calc elements just disappears.

What am I doing wrong? Or maybe my 'solution' is an overkill and it can be done way easier? Please help!

UPDATE It started to work but... it doesn't make much sense to me. I've hanged:

Code:
$title = $data['money_21_repeat___title_raw'];

to
Code:
$title = $data['money_21_repeat___title'];

...but in the if condition I still use the raw value! I don't know what's worse - if something doesn't work while it should, or the opposite.

Cheers,

Olek
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top