Closed (works as designed)
Project:
Views PHP
Version:
7.x-1.x-dev
Component:
Code
Priority:
Minor
Category:
Support request
Assigned:
Reporter:
Created:
14 Mar 2012 at 00:22 UTC
Updated:
23 May 2012 at 16:05 UTC
I have a user reference field. I wanted to compare if it is equal to the current user. If it is equal to the current user, it displays the string "Successful", otherwise, it displays "Unsuccessful". Originally, it was an issue, but while I typed in the code, I realized I had simply made a typo, but I decided to post it anyway for anyone else's benefit. I have this in the output code with php tags surrounding it:
$nid = $row->nid;
$node = node_load($row->nid);
global $user;
$yes = 'Successful';
$no = 'Unsuccessful';
$current_dude = $user->uid;
$winner_dude = $node->field_successful["und"][0]["uid"];
if($current_dude == $winner_dude)
{
echo $yes;
}
else
{
echo $no;
}
Comments
Comment #1
fehin commentedI tried your code but I got
Notice: Undefined index: uid in __lambda_func()error and the result is always "Unsuccessful". I'm using entity reference module for my user reference field.Comment #2
axgalloway commentedOh, I used the "Reference" module. I imagine something similar could be used for the entity reference module. Instead of "uid", it could be something like "value", or something else entirely. Look at your database and look for the name of column with the value you want to use. It should be something like field_fieldname_lastpart. Usually, it is the lastpart you will put in quotes, so in my example, in my database, it is something like field_successful_uid in the database.