Ramsesx Posted June 2, 2018 Posted June 2, 2018 In a pages database I have created 5 custom fields, each containing rating values from 1-10 and where the first key has no value in. Now I want to have the average overall rating calculated. "Field required" are set to no, so it's possible that only 2 values need to be calculated (or 3, 4 or 5).
TDBF Posted June 2, 2018 Posted June 2, 2018 56 minutes ago, Ramsesx said: In a pages database I have created 5 custom fields, each containing rating values from 1-10 and where the first key has no value in. Now I want to have the average overall rating calculated. "Field required" are set to no, so it's possible that only 2 values need to be calculated (or 3, 4 or 5). $cfield1 = 0; $cfield2 = 0; $cfield3 = 4; $cfield4 = 6; $cfield5 = 8; //How many numbers are in our set. $customFeildCount = 5; //Get the sum of Custom Fields. $totalCount = $cfield1 + $cfield2 + $cfield3 + $cfield4 + $cfield5 ; //Calculate the average by dividing $totalCount by the $customFeildCount . $average = $totalCount/ $customFeildCount ; echo $average; The above should give you a average of 3.6.
Ramsesx Posted June 2, 2018 Author Posted June 2, 2018 2 hours ago, TDBF said: $cfield1 = 0; $cfield2 = 0; $cfield3 = 4; $cfield4 = 6; $cfield5 = 8; //How many numbers are in our set. $customFeildCount = 5; //Get the sum of Custom Fields. $totalCount = $cfield1 + $cfield2 + $cfield3 + $cfield4 + $cfield5 ; //Calculate the average by dividing $totalCount by the $customFeildCount . $average = $totalCount/ $customFeildCount ; echo $average; The above should give you a average of 3.6. Thanks, I added this into the record template for testing but it doesn't shows anything: {{$cfield1 = 0;}} {{$cfield2 = 0;}} {{$cfield3 = 6;}} {{$cfield4 = 9;}} {{$cfield5 = 8;}} {{$customFeildCount = 5;}} {{$totalCount = $cfield1 + $cfield2 + $cfield3 + $cfield4 + $cfield5;}} {{$average = $totalCount / $customFeildCount;}} {{echo $average;}}
TDBF Posted June 2, 2018 Posted June 2, 2018 10 minutes ago, Ramsesx said: Thanks, I added this into the record template for testing but it doesn't shows anything: {{$cfield1 = 0;}} {{$cfield2 = 0;}} {{$cfield3 = 6;}} {{$cfield4 = 9;}} {{$cfield5 = 8;}} {{$customFeildCount = 5;}} {{$totalCount = $cfield1 + $cfield2 + $cfield3 + $cfield4 + $cfield5;}} {{$average = $totalCount / $customFeildCount;}} {{echo $average;}} I gave you the mathematical solution to your problem, there is no way I can know the custom field names which you used for the ratings etc ?
Recommended Posts
Archived
This topic is now archived and is closed to further replies.