/    Sign up×
Community /Pin to ProfileBookmark

Multiple If Statements

I want to do the following: If condition 1 and condition 2 and condition 3 are all met, then $error. I’m very new to php so fogive me if I didn’t phrase that in the best possible way. I’ve tried:

[code]if ($doc_len > 2000) {
} if ($doc_time==”12″) {
} if ($doc_service==”1″) {
$rateToBill = ‘Error!’;
}[/code]

but it only uses the last is statement and ignores all the others.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@SheldonJun 19.2007 — [code=php]
<?php
if(($doc_len > 2000) or ($doc_time == "12") or ($doc_service=="1")) {
$rateToBill = 'Error!';
}
?>
[/code]
Copy linkTweet thisAlerts:
@beachkitty85authorJun 19.2007 — Thanks so much for your help, but that code isn't exactly what I need. It will give an error message if ANY of the conditions are met. I need the error message to display when ALL the conditions are met.
Copy linkTweet thisAlerts:
@beachkitty85authorJun 19.2007 — Obviously enough, the correct code is
[code=php]if(($doc_len > 2000) and ($doc_time == "12") and ($doc_service=="1")) {
$rateToBill = 'Error!';
}[/code]

I don't know why I didn't think of it sooner. Sheldon, thanks so much for pointing me in the right direction.
Copy linkTweet thisAlerts:
@SheldonJun 19.2007 — Cool.
×

Success!

Help @beachkitty85 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...