SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mySQL: need help understanding WHERE AND OR

    Hello everyone,
    I've been doing some php programming lately and I have come in contact with a problem.
    I have a table called "friends" and in that table I got 'user_id' and 'friend_id', I now want to do a query to see if two id's match, like this:
    PHP Code:
    $sql "SELECT id FROM friends WHERE user_id = $me AND friend_id = $someone";
    $result mysqli_query($this->db,$sql);
    $length mysqli_num_rows($result);
    mysqli_free_result($result); 
    The only problem now is that the current user can only be 'user_id', so I think I may be able to use the OR statement to select rows with either $me/$someone as user_id or friend_id.. is this possible?

  2. #2
    SitePoint Addict aguroyz's Avatar
    Join Date
    Jan 2009
    Location
    Konoha Fire Country
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whats the friend id for??

  3. #3
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    WHERE user_id = $me AND friend_id = $someone OR user_id = $someone AND friend_id = $me
    Not exactly sure, but is this close to what you're looking for? Could you provide more examples/info?
    Cross browser css bugs

    Dan Schulz you will be missed

  4. #4
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aguroyz View Post
    whats the friend id for??
    I use the "friends" table to link two users together so the one who invited the other friend is 'user_id' and the friend is 'friend_id'.

    Quote Originally Posted by SoulScratch View Post
    Code:
    WHERE user_id = $me AND friend_id = $someone OR user_id = $someone AND friend_id = $me
    Not exactly sure, but is this close to what you're looking for? Could you provide more examples/info?
    I think thats exactly what I'm looking for, Thanks for the help.

  5. #5
    SitePoint Addict aguroyz's Avatar
    Join Date
    Jan 2009
    Location
    Konoha Fire Country
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    did soulscratch code worked??

  6. #6
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aguroyz View Post
    did soulscratch code worked??
    Yeah it works perfectly.

  7. #7
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome.
    Cross browser css bugs

    Dan Schulz you will be missed


Bookmarks

Posting Permissions

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