6

I have 2 integer fields in views , first field is 'field_code' and second field is 'field_rank', Finally I want filter views result, with views_php module. I use this code but it does not work,

$math = ($row->field_code / $row->field_rank) * 100;
if ($math < '30') { return TRUE; }

Please can someone help me to fix this problem.

5

It is a Drupal bug that is in active state until date but there are some work-arounds, one of them I am sharing with, if it could help you out. Use $data variable to access your fields value because $row only gives numbers, which appear to be node ID's (Drupal Bug).

Use the following code I wrote in Global:PHP 'filter code' text area

$field_code = $data->_field_data['nid']['entity']->field_code['und']['0']['value'];
$field_rank = $data->_field_data['nid']['entity']->field_rank['und']['0']['value'];

$math = ($field_code / $field_rank) * 100;
if ($math < '30') {
  return TRUE;   
  // If you dont want to display the result otherwise use FALSE in place of TRUE
} 

Use this code as it is in your view. It works perfect; I have tested it.

|improve this answer|||||
1

As I understand, you are facing the problem due to the D7 issue with $row values of returning NID instead of the expected field values. So, check once by printing if you are getting the expected values in the PHP field. If not then you can go for the below approach :

  1. Pass the field information through $view object like say, $view->RELEVANT_NAME = $data->RELEVANT_PATH

  2. Access these values in the PHP filter and write your conditions there

Hope it helps

|improve this answer|||||
  • Could you please be a little bit more accurate and tell where/how you pass the field info through $view object ? And maybe add a snippet of code? thanks in advance – Kojo Dec 8 '13 at 15:22

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.