...

View Full Version : Linking Users



brianjamesward
05-19-2011, 04:27 PM
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

$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...

Fumigator
05-19-2011, 08:01 PM
What about:



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)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum