Since I need about 20 of these calculations I've tried to come up with a script that cycles through arrays holding components of the calculations and field names I want to use. However, I can't get the below script to work:
When I try this sort of stuff (as am no guru) I find that doing things like this helps for some reason:
// NOT THIS:
$fields["'".$stats[$j]."_".$fieldcalc[$i]."'"]->value = $result;
$field_name = $stats[$j]."_".$fieldcalc[$i];
$fields[$field_name]->value = $result;
But that might be me covering up some crappy coding on my part....
Sorry for the late reply, I was travelling in Russia the last few days.
Your response definitely helped. I get the first row of results correctly now (the sums). The other calculations still don't return a result, yet. I'll continue to work on this and will post the final code here once I've got it to work correctly.
Thanks a lot for pointing me in the right direction to solve the issue of getting the field calls right, Bucklash! This code is now way more efficient than the 22 separate BeforeRender fields I used before. And it feels way more elegant. :-)