RE: [PHP] IF statement problems
| From: | Paul Hawkins | Date: | Mon, 31 Jul 2000 19:16:32 +0000 |
| Subject: | RE: [PHP] IF statement problems | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-9243@lists.php.net to get a copy of this message | ||
Not exactly re-typed, but I did edit out some of the data that wasn't
needed. And regarding the your the last 2 it should have been a 1 as well.
Anyway, I was able to solve the problem by using an "elseif"
Here is what worked.
if ($choice) {
if (($vname==1) AND ($div==1)) {
$value=1;
}elseif (($vname!=1) AND ($div!=1)) {
$value=4;
}
if (($vname==1) AND ($div!=1)) {
$value=2;
}
if (($vname!=1) AND ($div==1)) {
$value=3;
}
}
Combining the last one inside the first one with an "elseif" made it work
-Paul
-----Original Message-----
From: Benton Jackson [mailto:goatrider@goatrider.com]
Sent: Monday, July 31, 2000 12:10 PM
To: php-general@lists.php.net
Subject: RE: [PHP] IF statement problems
You mean you re-typed it for the message? You should try to cut-and-paste if
at all possible. If you re-type it, you are apt to type in what you think is
in the code, not what is really there. For example, one of the "{" could be
a "(", or a "!" could be a "|", but you copied what you meant to have.
Code
blindness is very insidious. I also notice that all the variables are
compared to 1, except for the last "$div!=2".
Anyways, your code could be a little more concise and efficient with ELSE
statments:
if ($choice) {
if ($vname==1) {
if ($div==1) {
$value=1;
} else {
$value=2;
}
} else if ($div==1) {
$value=3;
} else {
$value=4;
}
}
> From: Paul Hawkins [mailto:phawkins@californiasteel.com]
>
> Sorry about that, yes in the example I gave I'm missing the
> semicolon. But
> in the script it is there.
>
> From: Sam Masiello [mailto:smasiello@chekinc.com]
>
> You are missing a semicolon after $value=4
>
> -----Original Message-----
>
> I'm having a bit of trouble with an if statement generated from a few
> pull-down menus on a form. The two pull-downs set the variables
> $vname and
> $div. Based on the combination of their values I need to set a separate
> variable $value. The following IF statement works fine until I
> include the
> last if statement. IF the last IF statement is in the script it gets
> evaluated as true no matter what is selected on the form.
>
> Here is the code:
>
> if ($choice) {
> if (($vname==1) AND ($div==1)) {
> $value=1;
> }
> if (($vname==1) AND ($div!=1)) {
> $value=2;
> }
> if (($vname!=1) AND ($div==1)) {
> $value=3;
> }
> if (($vname!=1) AND ($div!=2)) { //bad if statement
> $value=4
> }
> }
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net