Dalían
Dalían

Reputation: 252

IF Statement - 2 conditions

I'm trying to write an if statement which is contingent on 2 conditions.

I have tried:

<?php if($nominated=='yes' || $approved=='no'): ?>

But this doesn't work as it displays results that have either, ie, all results which are nominated and all results which are not approved.

This is incorrect.

for example. there are 10 rows in total. 4 are nominated, 1 of those is approved. Using the above code pulls all 4, since the first criteria $nominated=='yes' is met. When I'm trying to pull only 1 row, the row which is nominated AND not approved.

Upvotes: 0

Views: 143

Answers (1)

MSadura
MSadura

Reputation: 1042

Here's the correct way to do what you are wanting to do:

if($nominated=='yes' && $approved=='no')

|| = OR - must satisfy only 1 condition to be true

&& = AND - both conditions must be satisfied in order to be true

If you would like to learn more about binary logical operators you can check this manual here

Upvotes: 3

Related Questions