Extract only a particular data

Antares74

Member
Hi,
i've two tables joined. 1st table contains users info, 2nd table contain repeated data for users
Each record of the data is composed of an amount and a checkbox.
To extract all the values of each individual user, I used a calc field with this code:

$amounts1 = (array) $data['pagamenti___importo_raw'];
return array_sum($amounts1);

Everything works.

Now I would like to extract only the values that have the corresponding checkbox flagged ... I can not find a solution to this problem.
Thanks for you support
 
There may be a more eloquent way of doing it with an array_map callback function or other php array functions. But how about just using a simple basic loop - something like this...
PHP:
$amounts1 = (array) $data['pagamenti___importo_raw'];
$checks1 = (array) $data['pagamenti___checkboxelement_raw'];
$total = $row = 0;
foreach($checks1 as $check){
  if($check == '1') $total = $total + $amounts1[$row];
  $row++;
}
return $total;
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top