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 acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard netgear network printer problem ram registry repair router slow software sound toshiba trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: PHP - IF statement with OR and OR

Reply  
Thread Tools
amanxman's Avatar
Senior Member with 690 posts.
 
Join Date: Mar 2006
Location: New Zealand
Experience: Advanced Web Developer
03-Nov-2009, 05: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 82 posts.
 
Join Date: Feb 2006
Location: New Jersey
Experience: Intermediate
03-Nov-2009, 05: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 690 posts.
 
Join Date: Mar 2006
Location: New Zealand
Experience: Advanced Web Developer
03-Nov-2009, 05:40 PM #3
you legend, you've just saved me hours of work.

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

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:04 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.