Reputation: 7994
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?
Upvotes: 52
Views: 169305
Reputation: 7768
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){
}
Upvotes: -2
Reputation: 11596
Make sure that the value of the column is really NULL and not an empty string or 0.
Upvotes: 3
Reputation: 11851
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.
Upvotes: 1
Reputation: 7187
Use is_null or ===
operator.
is_null($result['column'])
$result['column'] === NULL
Upvotes: 114