[PHP-DB] Ifs, ands, or buts

2003-08-27 Thread Diana Cassady
Another one that should be easy that I am just not finding anywhere in 
the manual.

How do I put an 'and' or an 'or' in an if statement?

I know I could achieve the same results with multiple if statements, 
but that seems so inefficient.

Lets say I wanted to check a bunch of fields to make sure they weren't 
empty. I can check one field by saying:

if ($field1) {
echo Field 1 is not empty;
}
Can't I just say:

if ($field1 and $field2 and $field3 and $field4) {
echo All four fields are field in;
}
Or

if ($field1 or $field2 or $field3 or $field4) {
echo At least one of the four fields is filled in;
}
?

Maybe its not the word and and or but maybe its  or || 
respectively? That's what I've seen in other languages that let you do 
this. I'm sure there must be a way to do this with PHP, too.

Thanks for your help.

Diana   
[EMAIL PROTECTED] Will Work for Chocolate
http://www.vivaladata.com   (and its worth every byte!)
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Ifs, ands, or buts

2003-08-27 Thread Matt Matijevich
http://www.php.net/manual/en/language.operators.logical.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Ifs, ands, or buts

2003-08-27 Thread Sebastian Haag
Diana,

Diana Cassady said:
 Another one that should be easy that I am just not finding anywhere in
 the manual.

 How do I put an 'and' or an 'or' in an if statement?

 I know I could achieve the same results with multiple if statements,
 but that seems so inefficient.

 Lets say I wanted to check a bunch of fields to make sure they weren't
 empty. I can check one field by saying:

 if ($field1) {
 echo Field 1 is not empty;
 }

 Can't I just say:

 if ($field1 and $field2 and $field3 and $field4) {
 echo All four fields are field in;
 }

 Or

 if ($field1 or $field2 or $field3 or $field4) {
 echo At least one of the four fields is filled in;
 }

 ?

 Maybe its not the word and and or but maybe its  or ||

You solved it yourself.  means 'AND' , || means 'OR'

 respectively? That's what I've seen in other languages that let you do
 this. I'm sure there must be a way to do this with PHP, too.

 Thanks for your help.

 Diana
 [EMAIL PROTECTED] Will Work for Chocolate
 http://www.vivaladata.com   (and its worth every byte!)

 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 

Once a problem is defined - it is half way solved. (Henry Ford)

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Ifs, ands, or buts

2003-08-27 Thread Jennifer Goodie
 Lets say I wanted to check a bunch of fields to make sure they weren't
 empty. I can check one field by saying:

 if ($field1) {
 echo Field 1 is not empty;
 }

I'd use empty() since certain values would cause your if to evalute to false
http://www.php.net/manual/en/function.empty.php
if(!empty($field1){

 Can't I just say:

 if ($field1 and $field2 and $field3 and $field4) {
 echo All four fields are field in;
 }

Have you tried it?
Once again, I'd use empty()
if(!empty($field1)  !empty($field2) !empty($field3) !empty($field4)){
I like '', rather than 'and', but that's just me.

 if ($field1 or $field2 or $field3 or $field4) {
 echo At least one of the four fields is filled in;
 }
See above but replace '' with '||' or 'or'

 Maybe its not the word and and or but maybe its  or ||
 respectively? That's what I've seen in other languages that let you do
 this. I'm sure there must be a way to do this with PHP, too.

http://www.php.net/manual/en/language.operators.logical.php

Tha manual is your friend, it can answer a lot of your questions.  Once
again, I don't see what this has to do with databases.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php