Global php view for conditional profile image I have tried to configure a view for a user listing.
In this view only few fields from the user entity will be shown. In the user entity I have a boolean variable. If the boolean variable is TRUE ("1") the real profile image should be shown, otherwise the default image for all users should be shown.

In order to implement it I have added a views field of type Global: PHP.  In the field's code I wrote:

$file = file_load($row-&gt;picture);
if(isset($row-&gt;field_primum) ) {
if($row-&gt;field_primum == "1") {
print theme('image', array('path' =&gt; $file-&gt;uri)); 
else ($row-&gt;field_primum == "2") {
print(&lt;a  src="/sites/all/themes/test_them/images/anonymous.jpg" height="42" width="42"&gt;&lt;/a&gt;);
}
}
}


However it runs only on the first user and not for all users in the display. Do you have any idea why?

Thanks
zanet
It's possibly the result of syntax errors.

This is where you can see the benefits of well formatted code.

If you format your code like this it becomes more obvious that you have errors in your code (I assume $row->picture actually is a file ID):

$file = file_load($row-&gt;picture);
if (isset($row-&gt;field_primum)) {
  if ($row-&gt;field_primum == "1") {
    print theme('image', array('path' =&gt; $file-&gt;uri)); 
    else ($row-&gt;field_primum == "2") {
      print(&lt;a src="/sites/all/themes/test_them/images/anonymous.jpg" height="42" width="42"&gt;&lt;/a&gt;);
    }
  }
}


Problems I can see now are:


There you can see that the else actually has no if statement because it is inside the second if statement.
The else also shouldn't have the condition. If it needs the condition then use elseif.
You mention that the field you are using is a boolean field, in which case the values will be 0 &amp; 1, not 1 &amp; 2.
The second print statement should be printing a string so the string should be wrapped in quotes.
You are incorrectly using the a tag to print an image. You should use an img tag for images and an a tag for links.


I would think it should be more like this:

if (isset($row-&gt;field_primum)) {
  if ($row-&gt;field_primum) {
    $file = file_load($row-&gt;picture);
    print theme('image', array('path' =&gt; $file-&gt;uri));
  }
  else { 
    print('&lt;img src="/sites/all/themes/test_them/images/anonymous.jpg" height="42" width="42" /&gt;');
  }
}


Note that I also moved the file_load() call inside the if statements because there is no need to load it if you aren't using it.