Jump to content


Photo

AND/OR Function


  • Please log in to reply
2 replies to this topic

#1 mcmuney

mcmuney
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 05 October 2006 - 11:37 PM

I need to make the where statement below and make it where the reverse is also possible, can someone help with rewriting the statement. It basically needs to be WHERE x=1 AND y=2 OR x=2 AND y=1 (it should look for either of these possibilities):

$query="select * from `sc_friend` where (scf_mem_id={$R}) and (scf_frnd_id={$social_mem_id})";


#2 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 05 October 2006 - 11:45 PM

where (((scf_mem_id={$R}) and (scf_frnd_id={$social_mem_id}) OR ((scf_mem_id={$R}) and (scf_frnd_id={$social_mem_id} ))

The section before and after teh OR are the same cause i dont understand what you are doing but that will work when you get the right stuff after the or

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 05 October 2006 - 11:47 PM

Something like this should work...

$query="SELECT * FROM `sc_friend` WHERE (x = 1 AND y = 2) OR (x = 2 AND y= 1)";

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users