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?
NULL essentially means a variable has no value assigned to it; false is a valid Boolean value, 0 is a valid integer value, and PHP has some fairly ugly conversions between 0 , "0" , "" , and false . Show activity on this post. Null is nothing, False is a bit, and 0 is (probably) 32 bits.
To check for null variables, you can use a strict equality operator ( === ) to compare the variable with null . This is demonstrated below, where the boolean expression evaluates to true for only for null and evaluates to false for other falsy values.
A field with a NULL value is a field with no value. If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value. Note: A NULL value is different from a zero value or a field that contains spaces.
Therefore you can use count() (if the object is Countable). Or by using get_object_vars() , e.g.
Use is_null or ===
operator.
is_null($result['column']) $result['column'] === NULL
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