SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Location
    Limbo
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Attempting to create a mutual friend list

    Hi there,

    I'm having trouble with some SQL logic for mutual friends.

    Say I have 2 variables, user1, and user2. What can I do to find out the mutual friends of these two users?

    My friends table is:

    friend1, friend 2, requestor and status.

    When someone is a friend with each other the entry goes both ways. So.
    friend1 = user1, friend2 =user2 AND friend1 = user2, friend2 = user1.

    Now how can I find a mutual friend? How can I take user1 = friend1 and take friend2 to check whether user2 is friends with friend2?

    Thanks for your help.

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Location
    Limbo
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    More specifically I was wondering whether there was any "IN COMMON" SQL commands.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2012
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm a beginner at this, so someone else can confirm or negate whether or not this method is advisable:

    If user1 and user2 are friends, and user2 goes to user1's page, pull the friends of user1 and user2 and compare them against each other in a loop. Then display the ones (if any) that are equal to one another (i.e. mutual friends).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •