repeater area calculation

samir1903 20 Dec, 2018
Hello everyone

basicly i need to calculate two points for each students result
this->data['result']=this->data['point1']+this->data['point1'];
does not work with repeater it looks like because it is an array value now how can i reach this array values like mpoint1, point2 and result?
custom code is empty this where i should put some php cods i guess

repeater area calculation image 1
repeater area calculation image 2
repeater area calculation image 3
healyhatman 20 Dec, 2018
Yes you will need PHP. Don't put it in a loop event if you want the total of ALL the things they've added, put it in the loop and edit it if you're saving a new database entry for each Model.
$total = 0;
foreach($this->data("Model") as $entry) {
$total += $entry["point1"] + $entry["point2"];
}
return $total;

Then you'll just use {var:php_name}

DON'T COPY PASTE FROM THE FORUMS.
samir1903 21 Dec, 2018
Thanks for anser

but i think it is not clear for me
are you telling to me, do not use loop event at all or just for calculation i need loop event
and how can make new connection

and how can i use this {var:php code]

??
healyhatman 21 Dec, 2018
Well do you want to save each repeater entry on its own, or do you want to add ALL of them together?
samir1903 21 Dec, 2018
User add student to evaluate with radio group points from 1 to 5
there is 16 questions
if user want to add another student evaluate again
finally when user send the document
it saves as stdent 1, point1,point2, result 70%
student 2, point1, point2, result, 80%
.....
depends on student number
this works without results
i cannot reach points to calculate them for each student
healyhatman 21 Dec, 2018
So each Model entry is saved individually then? In your loop event, in a PHP block
$entry = $this->get("loop_event11.row.Model");
$pointsTotal = $entry["point1"] + $entry["point2"];
return $pointsTotal;
Then you can use {var:php_name} (whatever you've called the PHP block) to get the returned $pointsTotal value.

If you wanted to get the value directly from the data, it's just an array. So
$model  = $this->data("Model");
// Loop through it or...
$model[0]["point1"] etc etc
samir1903 22 Dec, 2018
I dont know why but i think
$this->get("loop_event11.row.Model") 
does not work for me 😢


repeater area calculation image 4
repeater area calculation image 5
repeater area calculation image 6
repeater area calculation image 7
healyhatman 22 Dec, 2018
You didn't copy and paste that code did you? If you did delete it and type it manually.

If it still doesn't work, type
print_r($this->get("loop_event35.row"));
to see the data structure.

Also clear the data source from the save data action.
samir1903 22 Dec, 2018
yes in copied before 🤗
now it turns result 0
if i enter 5 and 6 for example
technicly does not work from some reason again

moroever print_r does not turn anything
samir1903 22 Dec, 2018
right now
$total=$this->data['Model'][0]["point1"];
return $total;
is working but how can i increase 0 depends on model loop_event no kind of foreach or loop?
healyhatman 22 Dec, 2018
Sorry in the loop it should be loop_event35.row.points1 + loop_even535.row.points2

I'm used to looping through data reads.
samir1903 23 Dec, 2018
from some reason get and set does not work with me maybe because my php version is 5.5
your answer loop_event35.row.points1 + loop_even535.row.points2 didint work if did corrrect
$model=$this->data['Model'];
$total=$model[0]["point1"]+$model[0]["point2"];
return $total;

this code in php block in loop event

db_save is
result:{var:php17}


is working but basicly i connot change the results for another students multiplied from repeater
repeater area calculation image 8
healyhatman 23 Dec, 2018
Come on man help me out here.

$this->get("loop_event35.row.points1") + etc etc
samir1903 23 Dec, 2018
you are a magician, thanks a lot 🤣
This topic is locked and no more replies can be posted.