tags:

views:

811

answers:

5

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?

A: 

is that really your code? you have a coding error and probably an error_log file

Scott Evernden
Im simply printing the checkbox. And its checked if the value is not null. It dosent seem to do that.. Hense it always goes into the first if statment
Shahmir Javaid
the code posted is missing a right paren and a right brace and i get down-voted for spotting that? *eyeroll*
Scott Evernden
Sry this might sound mean.. But i didnt ask for syntax problems.. I asked for the Null value.. And if there was syntax error.. the code will output the error. However said that i did see the bracket.. I didnt actually copy and paste my code.. it was more of a type it my self. PS it wasnt me who downvoted you :D
Shahmir Javaid
Edit fixed the ) and the }
Shahmir Javaid
+5  A: 

Use is_null or === operator.

is_null($result['column'])

$result['column'] === NULL
The Chairman
Nvm.... Ima twonk.. Figured it out :D... Il mark yours as answered
Shahmir Javaid
+1  A: 

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.

Joel
sry im using mysql_fetch_array()... put the wrong one in.. Editing now
Shahmir Javaid
+1  A: 

Make sure that the value of the column is really NULL and not an empty string or 0.

Tomas Markauskas
i had results in two places... Its late and my brain is blown up.. Exactly what i did to figure it out :D
Shahmir Javaid
A: 

How about using

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

fernyb