Calculating average speed

Last modified: March 25, 2009 - 18:04

D'Arcy Norman has a Computed Field example in which he calculates the average speed of a bike trip, rather than filling it in manually:

Computed Field settings (leaving other fields at their defaults):

  • Computed Code:$node_field[0]['value'] = ($node->field_distance[0]['value'] / $node->field_duration[0]['value']) * 60;
  • Check 'Store using the database settings below
  • Data Type: float
  • Data Length: 10,2
  • Default Value: 0
  • Check 'Sortable' to make the field sortable in views.

The end result can then be displayed in a sortable view.

 
 

Drupal is a registered trademark of Dries Buytaert.