Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Linking Users

  1. #1
    New Coder
    Join Date
    Feb 2011
    Posts
    64
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Linking Users

    Do you ever get that way were you keep thinking you know how to do it, then suddenly lose it? Well that's happening to me today, Im hoping somebody can help me.

    On twitter, as many of you are probably aware, you can follow people and in return get followed by people. Thats similar with the site i have created, however, What i want to do is to build a list of all the "connections" made by a user on the profiles. (like a friends list)

    Basically, connections meaning they follow somebody and that somebody is following them back.

    Is this possible with PHP?

    My follows table looks like this:

    id / user_id / followed_user_id / timestamp

    What i'm thinking so far: trying to grab the users that the profile_user is following but only the ones that are following back...

    This is what i tried by no luck... ( i think im way off the mark )

    PHP Code:
        
      <?php

      $profile_user_id 
    $_REQUEST['id'];
      
      
    $usersconnections mysql_query("SELECT * FROM `follows` WHERE `user_id` = '$profile_user_id'");
      
    $connections mysql_fetch_array($usersconnections);
      
      
    $findconnections mysql_query("SELECT *
    FROM `follows`
    WHERE `followed_user_id` = '$profile_user_id'
    AND `user_id` = '$connections[user_id]'
    OR `user_id` = '$profile_user_id'
    AND `followed_user_id` = '$connections[user_id]'
    "
    );

    $connect mysql_fetch_assoc($findconnections);

    echo 
    "$connect[user_id]";
      
      
    ?>
    It's a tough one to explain, i hope this makes sense. Let me know if you need more info...
    Last edited by brianjamesward; 05-19-2011 at 05:44 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    What about:

    Code:
    SELECT *
    FROM follows as f1
    WHERE f1.user_id = $profile_user_id
    AND EXISTS (
        SELECT 1 FROM follows as f2
        WHERE f2.user_id = f1.followed_user_id)


  •  

    Posting Permissions

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