I have 3 tables :
useractivitylog
id userid activity_type activity_id date
which will store all user activities.
requestfriend
opid userid friendid requesttime message source requesttype friendemail status
which will store friends details. userid and friendid can be the user's id. If user A has send friend's request to user B, then userid will contain the id of A and friendid will be the id of B. So anyway B is the friend of A and A is the friend of B.
auth_user_profiles
id user_id first_name last_name profileimage
which stores user profile information.
What I need is to select all my friends activities from useractivitylog table. I tried with the following query. But it didnt worked.
echo "select ua.*,rf.opid,aup.user_id,aup.first_name,aup.last_name,
aup.profileimage from useractivitylog as ua INNER JOIN requestfriend as rf
INNER JOIN auth_user_profiles as aup on
aup.user_id= IF (rf.userid='$userid',rf.friendid,rf.userid)
WHERE (rf.userid=$userid or rf.friendid=$userid)
and rf.status='2' and ua.userid!=$userid";
Here, $userid
is my user id. Actually what I want is to retrieve the profile information and the activities of users who are friends of mine. But know, it is returning all rows in useractivitylog table even if the userid is not in my friends list.
Can anyone help me to find an appropriate query for this. Thanks in advance.