I have the following SQL query which produces the result I need in PHPMyAdmin and but I am lost on how I can use this query in D7.

SELECT sum(month.field_oct_value)
FROM uc_orders u,  field_data_group_audience ga, field_data_field_oct month
WHERE u.uid = ga.entity_id
and u.order_id = month.entity_id
and ga.bundle='user'
and ga.group_audience_gid=10
and (u.order_status='pending' OR u.order_status='payment_received' OR u.order_status='completed')

The query pulls integer values from field_data_field_oct for orders created by users from specific groups. The output required is a single integer, being the sum of field_data_field_oct values retrieved.

I am looking at views_php as a way of using the above, because I will be using the resulting views panes in Panels. But my php/drupal code knowledge is poor (but improving).

If anyone has any pointers on how I would use the above as the value code and an example of output code for a views_php global PHP field, I would be very grateful.

For bonus points: Ideally I would like the GID to be pulled from the viewed node's group_audience field...

Cheers, Nick

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.