Hello,
I have two separate fields in a View:
1. Miles on Engine at Time of Purchase/Delivery (field_engine_hours_at_delivery)
2. Miles added to Engine After Purchase/Delivery (field_util_agg_engine_hours)
(1) is a standard integer field. (2) is fed by an aggregation of many other content items. My view is set to display these two values in a table, side by side.
I would like to now add those two fields to get a "Total Miles on Engine" value for the view. I tried adding a Views PHP field with the following PHP code, but the result that is returned is blank.
Value Code
$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_engine_hours_at_delivery'))) + array_pop(array_pop(field_get_items($entity_type, $entity, 'field_util_agg_engine_hours')));
Output Code
<?php
$display_output = $entity_field_item['value'];
?>I'm not very well-versed in PHP, so I'm sure I've got something amiss in that code. Can anyone clarify whether this can be done... and if it can, what I need to change in my code to make it work?
P.S., I also tried this version of the Value Code, but still did not get any result:
$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, '$row->field_engine_hours_at_delivery'))) + array_pop(array_pop(field_get_items($entity_type, $entity, '$row->field_util_agg_engine_hours')));
Thanks!
Comments
Comment #1
chi commentedI think it could be done with global math expression field which is provided by Views module.
Comment #2
rashmit sidhu commentedYou need to return value from "Value code" and print in "Output code".
Value code
Output Code
Hope this helps.
Thanks!
Comment #3
liam morland