Fix for Fix for Fix for Fix for Fix for Friends of friends code. Need up displaying user information

  1. <?php
  2. global $user;
  3. $rtid = 1; //Relationship type ID.
  4. $max = 5; //The amount of users to show on the block.
  5.  
  6. $user_rel = db_query("
  7. SELECT u.uid
  8. FROM {users} u
  9. LEFT JOIN {user_relationships} ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id)
  10. WHERE (ur.requester_id = %d OR ur.requestee_id = %d)
  11.  AND ur.approved = 1
  12.  AND ur.rtid = %d
  13.  AND u.status <> 0
  14. GROUP BY u.uid
  15. ORDER BY COUNT(ur.requester_id OR ur.requestee_id) DESC
  16. ", $user->uid, $user->uid, $rtid);
  17.  
  18. $user_rel_com = array();
  19. while ($value = db_fetch_array($user_rel)) {
  20.   $user_rel_com[] = $value;
  21. }
  22. //Exit if no users found.
  23. if (empty($user_rel_com)) {
  24.   return;
  25. }
  26.  
  27. foreach ($user_rel_com as $row) {
  28.   $req_req_id_list .= " OR ur.requester_id = " . $row['uid'] . " OR ur.requestee_id = " . $row['uid'];
  29.   $no_include_friends .= " AND u.uid <> ". $row['uid'];
  30. }
  31. //Trim the first " OR ".
  32. $req_req_id_list = drupal_substr($req_req_id_list, 4);
  33.  
  34. //Get all of the current user's friends' friends and order by how many times they show up in the list.
  35. $user_rel_rel = db_query("
  36. SELECT u.uid
  37. FROM {users} u
  38. LEFT JOIN {user_relationships} ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id)
  39. WHERE (%s)
  40.  AND ur.approved = 1
  41.  AND ur.rtid = %d
  42.  AND u.uid <> %d
  43.  %s
  44.  AND u.status <> 0
  45. GROUP BY u.uid
  46. ORDER BY COUNT(ur.requester_id OR ur.requestee_id) DESC
  47. ", $req_req_id_list, $rtid, $user->uid, $no_include_friends);
  48.  
  49. $user_rel_rel_com = array();
  50. while ($value = db_fetch_array($user_rel_rel)) {
  51.   $user_rel_rel_com[] = $value['uid'];
  52. }
  53.  
  54. //Scrambles the users non-randomly.  Does not scramble the user at the bottom of the list.
  55. $z = $user_rel_rel_com;
  56. $i = 0;
  57. foreach ($user_rel_rel_com as $v) {
  58.   $r = rand(0, 1);
  59.   if ($r === 1 && $user_rel_rel_com[$i + 1]) {
  60.     $z[$i] = $user_rel_rel_com[$i + 1];
  61.     $z[$i + 1] = $v;
  62.   }
  63.   $i++;
  64. }
  65.  
  66. if(count($user_rel_rel_com) < $max) {
  67. $max = count($user_rel_rel_com);
  68. }
  69.  
  70. for ($i = 0; $i < $max; $i++) {
  71.   if ($z[$i] != $user->uid) {
  72.     $account = user_load(array('uid' => $z[$i]));
  73.      $rows[] = array(theme('username', $account),
  74.                 $account->profile_age);
  75.  
  76.   }
  77. }
  78.  
  79. // De9ine edit
  80.  
  81. foreach($rows as $row){
  82.    print '<span class="some-class" style="clear:both;">username: '.$row[0].' age: '.$row[1].'</span>\n';
  83. }
  84. //Theme with CSS as appropriate.  "More" link is optional.
  85. echo '<span class="uymn">'. theme('item_list', $list) .'</span>';
  86. ?>

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.