Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Web Design & Development
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop driver dvd email error excel firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem processor ram recovery router safe mode screen slow sound spyware trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: PHP - IF statement with OR and OR

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

 
Thread Tools
amanxman's Avatar
Senior Member with 655 posts.
 
Join Date: Mar 2006
Location: New Zealand
Experience: Advanced Web Developer
03-Nov-2009, 04:11 PM #1
Solved: PHP - IF statement with OR and OR
Hey,

PHP statement:

variableA = 1 OR variableA = 2 AND variableB = Z AND variableC = N OR variableC = M

the above statement results in variable A being ignored if varaible C matches - because of the OR
i.e
Variable A = 1 or 2
AND Varaible B = Z
OR Variable C = M or N


what I want is variableA to apply, and then variableC to apply seperately
so:
Variable A = 1 or 2
AND Varaible B = Z
AND Variable C = M or N

is that possible? or do i need to split it down to two statements?

Ta
__________________
It deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht frist and lsat ltteer is at the rghit pclae. Tihs is bcuseae we do not raed ervey lteter by it slef but the wrod as a wlohe.
--------------
RB Web Works
SNewman's Avatar
Member with 57 posts.
 
Join Date: Feb 2006
Location: New Jersey
Experience: Intermediate
03-Nov-2009, 04:21 PM #2
Try applying parenthesis:

Code:
if( ( (variableA = 1 OR variableA = 2) AND (variableB = Z) ) AND ( variableC = N OR variableC = M ) )
See if that works.
amanxman's Avatar
Senior Member with 655 posts.
 
Join Date: Mar 2006
Location: New Zealand
Experience: Advanced Web Developer
03-Nov-2009, 04:40 PM #3
you legend, you've just saved me hours of work.

thanks
SNewman's Avatar
Member with 57 posts.
 
Join Date: Feb 2006
Location: New Jersey
Experience: Intermediate
03-Nov-2009, 04:48 PM #4
Glad I could help =)
Reply Bookmark and Share

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 11:01 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.