How to add link to create relationship in a view In my project, I have user relationship module installed. I created a view of online users. I then tried to include a link to enable users "add friends or create relationship" in the view by adding the following code 

 global $user;
  $opt = '';
  $requestee_id = $row-&gt;uid;
  $requester_id = $user-&gt;uid;
  if (user_is_logged_in()) {
    if ($requestee_id != $requester_id) {
      //for friend request button
      $relationships = user_relationships_load(array('between' =&gt; array($requester_id, $requestee_id)));
      if (empty($relationships)) {
        $opt = l(t('Add Friend') , "relationship/$requestee_id/request/1", array('html' =&gt; TRUE, 'absolute' =&gt; TRUE, 'query' =&gt; array('destination' =&gt; 'user/' . $requestee_id), 'attributes' =&gt; array('class' =&gt; array('ur-link add-friend-btn user_relationships_popup_link'))));
      }
      else {
        foreach ($relationships as $relationship) {
          if ($relationship-&gt;approved == 1 &amp;&amp; user_relationships_ui_check_access('view', NULL, $relationship)) {
            $opt = t('&lt;span class="already-frnd"&gt;Friends&lt;/span&gt;');
          }
        }
      }
    }
  }
  print $opt;  


When I try to create a relationship, i am informed that "this user does not exist". Please what could I be doing wrong. 

P.S: I have 2 relationships on my site.
Thanks in anticipation.
I found out this could be done without writing custom code. 

In the view:


I added a field, User:uid.
I unchecked "create a label" and "link this field to its user" 
Using Rewrite results, i checked Rewrite the output of this field and input "Add as friend". 
I checked the "Output this field as a link" and then added the path www.example.com/relationship/[uid]request/1?destination=user/[uid] 


That solved the issue.