How do you use 'AND/OR' in an if else PHP statement? Would it be:
1) AND
if ($status = 'clear' AND $pRent == 0) { mysql_query("UPDATE rent SET dNo = '$id', status = 'clear', colour = '#3C0' WHERE rent.id = $id"); }
2) OR
if ($status = 'clear' OR $pRent == 0) { mysql_query("UPDATE rent SET dNo = '$id', status = 'clear', colour = '#3C0' WHERE rent.id = $id"); }
In the logical AND ( && ) operator, if both conditions are true , then the if block will be executed. If one or both of the conditions are false , then the else block will be executed.
There is no limit to the number of && you use in a statement. So it will work with 4, 5, 100. It fails because some of the conditions are falsey.
When you combine each one of them with an IF statement, they read like this: AND – =IF(AND(Something is True, Something else is True), Value if True, Value if False) OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False) NOT – =IF(NOT(Something is True), Value if True, Value if False)
Yes. The answer is yes.
http://www.php.net/manual/en/language.operators.logical.php
Two things though:
&&
and ||
instead of and
and or
, but they work the same (safe for precedence).$status = 'clear'
should probably be $status == 'clear'
. =
is assignment, ==
is comparison.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With