Page 1 of 1
if x != a OR b doesn't work
Posted: Sat Mar 12, 2005 1:00 am
by bladecatcher
G'day All,
I've searched everywhere I can think of but can't find out why this does not work. Any help appreciated.
This code works fine but when I combine them in a if statement using OR (see below) it fails can you explain why please?
this works:
Code: Select all
<?php
print $filename ;
if (file_exists($filename)) {
print " File exists: " . $filename ;
if ($filename != "contact.php") {
print " NOT contact." ;
if ($filename != "search.php") {
print " NOT search." ;
include "disclaimer.htm" ;
} else {
print " IS search." ;
}
} else {
print " IS contact." ;
}
}
?>
this doesn't work. why?
Code: Select all
<?php
print $filename ;
$contact = "contact.php" ;
$search = "search.php" ;
if (file_exists($filename)) {
print " File exists: " . $filename ;
if ($filename != $contact OR $search) {
print " NOT contact or search." ;
include "disclaimer.htm" ;
} else {
print " IS contact or search." ;
}
}
?>
Thanking you in anticipation,
bladecatcher
Posted: Sat Mar 12, 2005 1:06 am
by infolock
your second variable ($search) is not getting checked against anything.
So this
Code: Select all
if ($filename != $contact OR $search) {
should actually be this
Code: Select all
if ($filename != $contact || $filename != $search) {
you could use || and OR. Both work the same way... Hope this helps.
could you possible post an error message?
if x != a OR b doesn't work
Posted: Sat Mar 12, 2005 1:22 am
by bladecatcher
G'day,
WOW, this place IS busy.
Thank you very much for the instant reply.
still no go
Code: Select all
if ($filename != $contact || $filename != $search) {
does not work
but
Code: Select all
if ($filename != $contact AND $filename != $search)
does! Can someone explain why? Please
tia
bladecatcher
Posted: Sat Mar 12, 2005 1:34 am
by John Cartwright
Perhaps it is an error in your logic?
You should also use && instead of AND aswell..
Posted: Sat Mar 12, 2005 1:37 am
by infolock
just went ahead and deleted my failure of an attempt to explain that. someone with a better descriptive mind should tackle that one. too early in the morning and i'm about to pass out at the keyboard as it is lol...
quick note though.. && and AND are both ok and work the same. i guess it's just according to whatever you are most comfortable with...
anyways, GNITE
edit: as feyd has pointed out, i am wrong (but not real suprise here...)
http://us2.php.net/if <-- the bottom statement left me thinking that what i had originally said was true, and i didn't actually do any research on the issue. i guess i also missed the very top message warning of using the "and" and "or" statements lol..
in other words, when ur mind turns blank, get some sleep.
Posted: Sat Mar 12, 2005 2:37 am
by feyd
there is a difference between || and OR, && and AND .. it's called precedence:
http://php.net/language.operators#langu ... precedence
Thank you all very much
Posted: Sat Mar 12, 2005 4:53 am
by bladecatcher
G'day again,
I've eaten now and brain has been nourished, I see all.
Well, my mistake anyway. If it was an "=" and not "!=" the "OR" would have been correct, I think "+" and "-" terminals on my brain got crossed, lol. I'd previously read the manual on precedence and come to the conclusion the "OR" and "AND" were appropriate here, the bars and ampersands would be appropriate where "precedence" is required, correct?
Now I want to read a txt file of pages into an array and parse that so I'd better get started, THANKS again.
cheers,
bladecatcher
PHP tags
Posted: Sat Mar 12, 2005 4:59 am
by bladecatcher
BTW,
first time I viewed the post my php tags didn't appear to work.
This is a test, please ignore.
Code: Select all
if (file_exists($filename)) {
// if ($filename != $contact || $filename != $search) {
if ($filename != $contact AND $filename != $search) {
include "disclaimer.htm" ;
}
}
blade
Re: PHP tags
Posted: Sat Mar 12, 2005 5:25 am
by Weirdan
bladecatcher wrote:BTW,
first time I viewed the post my php tags didn't appear to work.
PHP tags mod has been redone recently. You might have been viewing the topic while old posts had been fixed.
Posted: Sat Mar 12, 2005 8:40 am
by feyd
re: ^ and ^^ ..
some recently older browsers and current browsers (depeding on operating system and such) may have an initial issue due to the speed, or lack thereof, of the data coming across. For instance with the old code, it happened quite frequently that Firefox would render the page before it processed the highlighting. Thus making the display a few pixels high. A quick page refresh always seemed to fix the problem. I personally haven't had any issue with this in the new code with Firefox 1.0.1 (Win32). I know I used to with Firefox 0.8 - 0.9 (Win32)