Thursday, 3 March 2011

getting a mutual friend list using custom sql query in drupal


i am using drupal UR module to implement the friends relations.below sql query is used to display mutual friend list. create custom module use this sql query and get the mutual friend list.

(SELECT user_relationships.rid AS rid, AS users_user_relationships_name, users_user_relationships.uid AS users_user_relationships_uid, user_relationship_types_user_relationships.plural_name AS user_relationship_types_user_relationships_plural_name FROM user_relationships user_relationships LEFT JOIN users users_user_relationships ON user_relationships.requestee_id = users_user_relationships.uid LEFT JOIN users users_user_relationships_1 ON user_relationships.requester_id = users_user_relationships_1.uid LEFT JOIN user_relationship_types user_relationship_types_user_relationships ON user_relationships.rtid = user_relationship_types_user_relationships.rtid WHERE (user_relationships.approved = '$user->uid') AND (user_relationships.requester_id = arg(1)) OR (user_relationships.requester_id = build) GROUP BY users_user_relationships_uid HAVING count(*) = '2' ORDER BY user_relationship_types_user_relationships_plural_name ASC )

No comments:

Post a Comment