I cannot get proper results from View PHP field.
I’ve set up a Flipped Table view of entity form submission of which I’m trying to calculate “results” (sum and count(for avg)) with following code
$results = array(); // For results
$static = get_object_vars($row);
dsm($static);
foreach($static as $key => $value) {
if(strpos($key,'field_') !== FALSE){
if($value !== NULL){
$results[$static['entityform_id']]['count']++; // Count no. of fields
$results[$static['entityform_id']]['sum']= $results[$static['entityform_id']]['sum']+$value; // Count sum of field values
}
}
}
return json_encode($results[$static['entityform_id']]);
which results:
{"count":55,"sum":55} {"count":55,"sum":110} {"count":55,"sum":165} {"count":55,"sum":220}
At this point I do not understand that why sum is always row index * sum? Eg.1 =55, 2=110, 3=165… All the submissions have the same fields and field values (clones) which explaines sums but I can’t figure out that where this multiplication “logic” happens?
It seems like it is looping/counting all four result rows every time.