$sql = "SELECT
u.new_userid
, u.fname
, u.lname
, u.email
, u.img_small
, u.seouname
FROM fb_users u
INNER JOIN fb_user_friends uf
ON uf.user = u.new_userid
WHERE u.new_userid <> $profileUserID
UNION
SELECT
u.new_userid
, u.fname
, u.lname
, u.email
, u.img_small
, u.seouname
FROM fb_users u
INNER JOIN fb_club_users cu
ON cu.new_userid = u.new_userid
INNER JOIN
(SELECT
clubid
FROM fb_club_users
WHERE new_userid = $profileUserID
) AS c
ON c.clubid = cu.clubid
WHERE u.new_userid <> $profileUserID";
It allmost works like a charm but… In this part:
INNER JOIN fb_user_friends uf
ON uf.user = u.new_userid
WHERE u.new_userid <> $profileUserID
… it goes wrong.
The table fb_user_friends looks like this: id, user, friend
Now I only want to get friend out of the table where the user i the current “$profileUserID”, but as it is now, it pulls all the “friend” records… Where do I go wrong?
maybe we could step back just a tiny bit and start over
what is the entire ~first~ query supposed to do?
in words, please
also, are you storing two rows for each relationship, or is each relationship uni-directional?
in other words, if humpty is friends with dumpty, how do you decide whether humpty goes into the user column and dumpty in the friend column, or vice versa? or both?
The first query, before UNION, is supposed to get all the current user friends from the table fb_user_friends where the current user is listed as “user”.
are you storing two rows for each relationship, or is each relationship uni-directional?
As it is now, I’m storing two records for each relationship, but I guess I could just use one!? It is on a trial basis so it could be changed with no fuss if it helps the process…
SELECT u.new_userid
, u.fname
, u.lname
, u.email
, u.img_small
, u.seouname
FROM fb_user_friends AS uf
INNER
JOIN fb_users AS u
ON u.new_userid = uf.friend
WHERE uf.user = $profileUserID
somewhat different from your first query, yes?
can you do the second query?
that’s fine, that’s actually more efficient for the queries