Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of OR 4

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Can the OR statement be used in PHP to replace this that does not work, but an example:

if ($_SESSION['DB6']>0) or ($_SESSION['DB12']>0) or ($_SESSION['DB22']>0){
echo "Something, Title or whatever"<br>\n";
}

See who's first on this one. Thanks
 
DO NOT use the "OR" operator in this context. Instead use the "||" logical-or operator.

"OR" and "||", although performing the same logical-or operation, have different precedence -- "OR" has a much lower precedence than "||". "OR" is better reserved for operations like:

mysql_query($somequery) or die(...);

See

But if you use the operator with appropriate precedence:

if ($_SESSION['DB6']>0) || ($_SESSION['DB12']>0) || ($_SESSION['DB22']>0){

then the condition is saying: "If any of the three variables is greater than 0"

Is this what you want, or should I remind you about our discussion this morning on isset() and array_key_exists()?

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Fingers Crossed:

Code:
if (($_SESSION['DB6']>0 or $_SESSION['DB12']>0) or  ($_SESSION['DB22']>0)){
        echo "Something, Title or whatever"<br>\n";

Thanks,
--Mark
 
Thanks sleipnir, a good clear answer.

Re: isset() and array_key_exists(), no, I've taken that on board, thanks again.

Thanks Mark, but I will stay away from using OR in the code.


Regards
 
Problem:

With this:

if ($_SESSION['DB6']>0) || ($_SESSION['DB12']>0) || ($_SESSION['DB22']>0) {
echo "Notify"<br>\n";
}

I get this:
Parse error: parse error, unexpected T_BOOLEAN_OR

Any ideas, thanks

 
If sentences in PHP are surrounded by parenthesis and followed by an opening curly brace. Now, let's look at your code:
Code:
if [b][blue]($_SESSION['DB6']>0)[/blue][/b] || ($_SESSION['DB12']>0) ||  ($_SESSION['DB22']>0) {
        echo "Notify"<br>\n";
}
The blue part shows what PHP understands as the if clause. From then on, it is looking for a curly brace, however, it has to deal with something it doesn't understand at all and barfs up the error. If you tell PHP what exactly is your condition, it will work:
Code:
if [blue][b]([/b]($_SESSION['DB6']>0) || ($_SESSION['DB12']>0) ||  ($_SESSION['DB22']>0)[b])[/b][/blue] {
        echo "Notify"<br>\n";
}
 
Thanks Vragabond, get the idea.

One thing, how do you get the character |, I just cut and pasted that one. I have been all round my keyboard, and guess there is a control and something else to press, as it's not on any one of my keys??

Thanks
 
Look on the standard 104-key keyboard. The key should appear in the rightmost position of the second-to-the-top main keyboard row. The key is above "enter" and below "backspace".

It should appear on a key that has the backslash.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ah, never noticed that key before. However how do I get the character. If I press it on it's own I get ` if I hold down shift and press I get ~ If I hold Alt and press I get nothing,
nor any other combination. Don't tell me I've got the rest of my life as a cut and paste person. I will nose around control panel and see what I find?
 
Not the backtick/tilde key, which is on the far lefthand side of the keyboard.

From that backtick/tilde key, go down one row. Go all the way to the righthand end of that row of keys. You will have a backslash/pipe ("\" / "|") key.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Keyboard fixed, works okay. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top