Copy link to clipboard
Copied
I need to search for a user and bring his details up only if he is in another user's friends list.
I have a user table with user_id, user_fname, user_sname etc.. and a friends table with friend_id, ur_id, their_id, approved
I have a ajax called php script to auto populate based on key pressing the letters that match the query.
Here is the query:
SELECT user_id, user_fname, user_sname, user_city, photo, email FROM users, friends WHERE ur_id = '$_SESSION[user_id]' AND user_fname LIKE '%$queryString2%' OR user_sname LIKE '%$queryString2%'
I seem to get all values, and doubles when I use this method, I dont think I can use a left join as I cant put the user_id and ur_id over each other.
Please can someone help me with this?
Thank you.
Yes I saw that, but that only checks one table for a certain value (value of $_SESSION["user_id"]).
But when you pull data from second table, you need to match a common value between tables, which is user_id in your case.
You will pull the data from 2nd table ONLY if 2nd table's user_id is same with the 1st tables user_id.
Copy link to clipboard
Copied
If I get it right, you will need one more condition on your WHERE clause:
ur_id = user_id
This way mysql will only pull data with same user ids
Copy link to clipboard
Copied
hi,
I already have ur_id = '$_SESSION[user_id]'
Copy link to clipboard
Copied
Yes I saw that, but that only checks one table for a certain value (value of $_SESSION["user_id"]).
But when you pull data from second table, you need to match a common value between tables, which is user_id in your case.
You will pull the data from 2nd table ONLY if 2nd table's user_id is same with the 1st tables user_id.
Copy link to clipboard
Copied
thank you, that works fine, I should have realised.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more