Results 1 to 2 of 2

Thread: Search users

  1. #1
    Join Date
    Dec 2011

    Unanswered: Search users

    Hi All,

    I am making a kind of dating site. Users can add friends and here i have a problem.

    When the user types a letter of the name they are searching for in the input box. There is a request made to my php file that returns 6 users that contain the letters of the user input.

    I use this query to search for users:
     select id_user, username from users where username like '%".mysql_real_escape_string($find_user_name)."%' LIMIT 6
    The problem is that the users that are already friends also are returned.

    My database:
    Table users: id_user, user_name, email, ..., ....
    Table friends: users_id_user, friend_id

    I thought about making a view of users and then removing the ids that are in my friend_id and then use the view to search for new friends. Is there a better way of doing this?

    Thanks in advance!


  2. #2
    Join Date
    Oct 2011
    Hamburg, Germany
    you can join the friend table in your query
    select * 
    from user u
    left join friend f on f.user_id = u.user_id
    f. friend_id  is null   --so you can see when user has no friends
    and username like '%".mysql_real_escape_string($find_user_name)."%' 
    LIMIT 6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts