PHP Check for NULL


Question

Here is the below Code:

$query = mysql_query("SELECT * FROM tablex");

if ($result = mysql_fetch_array($query)){

    if ($result['column'] == NULL) { print "<input type='checkbox' />"; }
    else { print "<input type='checkbox' checked />"; }
}

If the values are NOT NULL i still get the uncheked box. Am i doing something wrong from above, shoudnt $result['column'] == NULL work?

Any Ideas?

1
37
10/16/2009 6:40:58 AM

Accepted Answer

Use is_null or === operator.

is_null($result['column'])

$result['column'] === NULL
81
10/16/2009 5:42:20 AM

How about using

if (empty($result['column']))


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon