0% found this document useful (0 votes)
22 views

Drupal 7 Views PHP Using Global PHP Fields

This document discusses using PHP code in Views global fields in Drupal 7 to output custom data from the database. It explains that the available variables in global PHP fields only return the node ID, not other field values. It provides code to print_r all available data to find the needed field values. The solution code shown queries the database to sum cost budget values matching two node field values, and outputs the result. The document notes some limitations of global PHP fields and hopes to find answers to additional issues.

Uploaded by

SetyawanWawan78
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Drupal 7 Views PHP Using Global PHP Fields

This document discusses using PHP code in Views global fields in Drupal 7 to output custom data from the database. It explains that the available variables in global PHP fields only return the node ID, not other field values. It provides code to print_r all available data to find the needed field values. The solution code shown queries the database to sum cost budget values matching two node field values, and outputs the result. The document notes some limitations of global PHP fields and hopes to find answers to additional issues.

Uploaded by

SetyawanWawan78
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Drupal 7 + views PHP using global PHP fields | CVRC | David Leary Documentation

9/5/2013

Drupal 7 + views PHP using global PHP fields


Created on May 24, 2012 W ritten by admin

Background: Drupal 7 using views PHP and Global: PHP fields. Problem: For some reason, and I dont know why, the available variables, shown in the field below value code and output code, in global php field return the NID, and not the actual value. I also do not understand the difference between the value code and the output code. They interpret the exact same code differently and I find it extremely annoying. So I default to using the output code only. This will be a headache if you have to reuse the value you output. Why am I doing this? I need to run queries on the tables in the drupal database for financial analysis. Solution: So if the available variables are not what you need then how do you find what you need? Its simple, add this code to the output code field: <?php print_r($data); ?> What this does is spits out all the available data values and you have to muddle through it to find the data you need. You can drill down farther if you need to: <?php print_r($data->field_field_whateverfield); ?> In my case, this was the winning solution: $data->field_field_project_number_s['0']['raw']['value']; My final code in the output code field: <?php $pn = $data->field_field_project_number_s['0']['raw']['value']; $an = $data->field_field_award_number_s['0']['raw']['value']; $tcb = db_query(" SELECT SUM( field_cost_budget_value ) FROM field_data_field_cost_budget, field_data_field_award_number_s, field_data_field_project_number_s WHERE field_award_number_s_value = '$an' AND field_project_number_s_value = '$pn' AND field_data_field_cost_budget.entity_id = field_data_field_award_number_s.entity_id AND field_data_field_cost_budget.entity_id = field_data_field_project_number_s.entity_id")->fetchField(); print $tcb; ?> Remember, this only prints the variable $tcb. You will not be able to access $tcb again. I havent found a solution for this either. Hopefully I can find answers to some of these issues, if so I will post.

http://blog.cvrc.virginia.edu/?q=node/13

1/1

You might also like