RE: [PHP] IF statement problems
| From: | Benton Jackson | Date: | Mon, 31 Jul 2000 19:09:39 +0000 |
| Subject: | RE: [PHP] IF statement problems | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-9240@lists.php.net to get a copy of this message | ||
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
> }
> }