I have a fivestar field that needs to be an average of 5 other fivestar fields. I have read;

-Using Fivestar to get votes to show

-Combine Multiple Fivestar rating fields,

-Average Value of Multiaxes

None of those really walks you through the process of creating a field that will total all other votes. I need to pull the values from the database, average them, save that 'average' to the database so it can be searchable, and then display that average on the content type am rating.

Am using the latest Drupal 7, fivestar, votingapi, computed field, etc... I've tried many different approaches to this and the only thing that has come close was some custom php I wrote that gives me an average of all the other fivestar fields. The problem with that is it doesnt save into the database.

EDIT: This is the PHP code I use to display the average. Technically its an average of averages. But it works. Unfortunately, it doesn't store in the DB.

$total = 
        $content['field_business_q1'][0]['user']['#item']['average'] + 
        $content['field_business_q2'][0]['user']['#item']['average'] +
        $content['field_business_q3'][0]['user']['#item']['average'] +
        $content['field_business_q4'][0]['user']['#item']['average'] +
        $content['field_business_q5'][0]['user']['#item']['average'] +
        $total = $total / 6;
        echo "<b>Total Average:</b> " . $total;
  • Why not post your custom code? Commented May 4, 2012 at 23:38
  • I have posted the custom code. It is the same as my question in regards to the computed field. Commented May 8, 2012 at 16:19


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.