Drupal 7 using views PHP and Global: PHP fields.
For some reason, and I don’t 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.
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:
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:
In my case, this was the winning solution:
My final code in the output code field:
$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();
Remember, this only prints the variable $tcb. You will not be able to access $tcb again. I haven’t found a solution for this either. Hopefully I can find answers to some of these issues, if so I will post.