/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Multiple conditions in if statement

I would like to check for people who are on leave (maternity or loa) but do not have the title: partners, associates, counsel, articling students, & summer students. My code checks for the maternity and loa but not the title.

[code=php]if (($maternity == ‘x’ || $loa == ‘x’) && ($title != ‘Partner’ || ‘Associate’ || ‘Counsel’ || ‘Articling Student’ || ‘Summer Student’)) {[/code]

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@ZABIMar 05.2012 — [code=php]
if (($maternity == 'x' || $loa == 'x') && ($title != 'Partner' || $title != 'Associate' || $title != 'Counsel' || $title != 'Articling Student' || $title != 'Summer Student')) {
[/code]
Copy linkTweet thisAlerts:
@NoEffinWayMar 05.2012 — What immediatly came to my head:
[code=php]if ($maternity == 'x' || $loa == 'x') {
if($title != 'Partner' || 'Associate' || 'Counsel' || 'Articling Student' || 'Summer Student'){
//Do some cool stuff. XD
}
}[/code]
Copy linkTweet thisAlerts:
@beylahauthorMar 05.2012 — I have tried both your suggestions and neither works. For example, if they are a partner and on maternity leave they are not ignored.
Copy linkTweet thisAlerts:
@NogDogMar 05.2012 — [code=php]
if (
($maternity == 'x' or $loa == 'x') and
in_array($title, array(
'Partner',
'Associate',
'Counsel',
'Articling Student',
'Summer Student'
) == false
) {
// do stuff
}
[/code]
Copy linkTweet thisAlerts:
@ehimeMar 05.2012 — Good one Nog, I use in_array filtering alot, its a cheap way to invalidate.
Copy linkTweet thisAlerts:
@beylahauthorMar 05.2012 — I am getting an unexpected '{' error

when using the array filter

here is the full code

[code=php]if (
($maternity == 'x' or $loa == 'x') and
in_array($title, array(
'Partner',
'Associate',
'Counsel',
'Articling Student',
'Summer Student'
) == false
) {
echo '
<tr bgcolor="'.$rowColor.'">
<td>'.$name.'</td>
<td style="color:#666666">mapit</td>
'.$leave.'
<td>'.$title.'</td>
<td>'.$department.'</td>
<td>&nbsp;'.$floor.'</td>
<td>&nbsp;'.$timekeeper.'</td>
</tr>';
} else {
echo '
<tr bgcolor="'.$rowColor.'">
<td>'.$name.'</td>
<td><a href="'.$rows['floor'].'.php?id='.$rows['id'].'" target="_blank">mapit</a></td>
<td>'.$phone.'</td>
<td>&nbsp;'.$assistant.'</td>
<td>&nbsp;'.$assistantphone.'</td>
<td>&nbsp;'.$lawyer1.'</td>
<td>&nbsp;'.$lawyer2.'</td>
<td>&nbsp;'.$lawyer3.'</td>
<td>'.$title.'</td>
<td>'.$department.'</td>
<td>&nbsp;'.$floor.'</td>
<td>&nbsp;'.$timekeeper.'</td>
</tr>';
}[/code]
Copy linkTweet thisAlerts:
@beylahauthorMar 05.2012 — i found the problem a missing ")" after "false"

but i now get the following error:

Warning: in_array() [function.in-array]: Wrong datatype for second argument in C
Copy linkTweet thisAlerts:
@ehimeMar 05.2012 — [code=php]
$filter=array('Partner', 'Associate', 'Counsel', 'Articling Student', 'Summer Student');

if (
($maternity == 'x' || $loa == 'x') &&
in_array($title, $filter) == false
) {
echo "<tr bgcolor='{$rowColor}'><td>{$name}</td><td style='color:#666666'>mapit</td>{$leave}<td>{$title}</td><td>{$department}</td><td>&nbsp;{$floor}</td><td>&nbsp;{$timekeeper}</td></tr>";
} else {
echo "<tr bgcolor='{$rowColor}'><td>{$name}</td><td><a href='{$rows['floor']}' id='{$rows['id']}' target='_blank'>mapit</a></td><td>{$phone}</td><td>&nbsp;{$assistant}</td><td>&nbsp;{$assistantphone}</td><td>&nbsp;{$lawyer1}</td><td>&nbsp;{$lawyer2}</td><td>&nbsp;{$lawyer3}</td><td>{$title}</td><td>{$department}</td><td>&nbsp;{$floor}</td><td>&nbsp;{$timekeeper}</td></tr>";
}

[/code]
Copy linkTweet thisAlerts:
@beylahauthorMar 05.2012 — that worked perfectly - and now i understand it better as well especially with the word you chose "filter" - its a pretty little package now

thanks so much
Copy linkTweet thisAlerts:
@ehimeMar 05.2012 — Yeup.

and @Nog, I noticed a few times that on certain peoples installs, in_array doesn't like the array to be declared inline.

Stupid but whatever.....
Copy linkTweet thisAlerts:
@beylahauthorMar 05.2012 — all done thanks to all
Copy linkTweet thisAlerts:
@NogDogMar 05.2012 — Just goes to show that I like to use the Microsoft method of testing: send it out to the users and let them find the bugs. ?
×

Success!

Help @beylah 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 5.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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