wat wil i do so dat this condition will work. it gives me an error: undefined index: viewPHP Code:if($_GET['view'] == 'login' or !isset($_GET['view']))
wat wil i do so dat this condition will work. it gives me an error: undefined index: viewPHP Code:if($_GET['view'] == 'login' or !isset($_GET['view']))
You need to actually reverse your statement. When PHP encounters what you have programmed now and $_GET['view'] is not set, it gives you the error.
Code:if(!isset($_GET['view']) || $_GET['view'] == 'login')
gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer
whew. thnx. it works. wats d explanation there?
When you do something like if (condition 1 or condition 2 or condition 3...) the conditions are evaluated in order from left to right. So, if there's an error in condition 1, it will never reach condition 2 or 3. Since $_GET['view'] is not set, your condition 1 has an error - you are trying to operate on something that doesn't exist.
gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer
I actually think they added "and" and "or" in one of the recent PHP versions, but I could be wrong. I prefer the symbol syntax because I've used a lot of other C type languages and I'm stuck in my ways :P
Edit:
http://www.php.net/manual/en/languag...rs.logical.php
I would still stick to the || operator because "or" operates differently.
Last edited by garrettroyce; 05-20-2009 at 03:07 PM. Reason: Automerged Doublepost
gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer
hmmm. but i've read you can use 'or' and 'and' in the latest version. tnx guys for mor info
Feel free to use 'and' and 'or' forms when necessary if you understand operator precedence and can add explicit parentheses to:
so the parenthesized versions are parsed equivalently.Code:$foo='a' or false ? 'b' : 'c' and 'd'; $bar='a' || false ? 'b' : 'c' && 'd';
In general, you'll use '&&' and '||' much more than 'and' and 'or'. If you don't understand precedence, you should study it before going much further.