Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

mysql two table help

Participant ,
Jun 25, 2010 Jun 25, 2010

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.

TOPICS
Server side applications
524
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jun 28, 2010 Jun 28, 2010

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.

Translate
Guest
Jun 25, 2010 Jun 25, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 28, 2010 Jun 28, 2010

hi,

I already have ur_id =  '$_SESSION[user_id]'

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 28, 2010 Jun 28, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 28, 2010 Jun 28, 2010
LATEST

thank you, that works fine, I should have realised.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines