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?
Make sure that the value of the column is really NULL and not an empty string or 0.
Sometimes, when I know that I am working with numbers, I use this logic (if result is not greater than zero
):
if (!$result['column']>0){
}
How about using
if (empty($result['column']))
I think you want to use
mysql_fetch_assoc($query)
rather than
mysql_fetch_row($query)
The latter returns an normal array index by integers, whereas the former returns an associative array, index by the field names.
Source: Stackoverflow.com