methuselah methuselah - 1 month ago 8
PHP Question

using AND/OR in if else PHP statement

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");
}


many thanks in advance!

Answer

Yes. The answer is yes.
http://www.php.net/manual/en/language.operators.logical.php


Two things though:

  • Many programmers prefer && 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.
Comments