Jump to content


Photo

Using multiple conditions in SELECT statement


  • Please log in to reply
1 reply to this topic

#1 Tjk

Tjk
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 16 May 2006 - 07:42 PM

I'm having a problem with this little statement and I was wondering if someone could put me right on where i'm going wrong.

$query= mysql_query("SELECT * from friend WHERE {friend1='$userid' AND friend2='$_POST[friend]'} OR {friend1='$_POST[friend] AND friend2='$userid'}")or die("could not select friends record from friends");

I only want to select the record (and as i have it setup there can only be one record) where either the user of the page's id is in either friend1 or friend 2 and the other use that they have selected in a pulldown list is in the other friend column.

So for example if user of the page's id was 1 and the person they had selected had an id of 3 then it would select either when friend1 has the id 1 and friend2 has the id3 in it or friend1 has the id of 3 and friend 2 has the id of 1.

Hope this is clear enough for you to understand. Help appreciated as always.

-Tjk


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 16 May 2006 - 07:50 PM

Looks fine to me -- but you should be using parentheses, not curlies.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users