mardi 28 février 2017

The statement "if this OR that do X" won't work in PHP

I'm trying to show some information on screen only if a certain field is not null or if it doesn't say the word "null". I'm working with a PHP script.

For some reason I have a database that has some values set as null as a string, instead as a real NULL value. As there are many items and I still don't know what causes to set the field as "null" instead of NULL, it's going to be easier to just set that with an if statement for the time being.

But for some reason, this is not working:

if ($row['cronograma'] != NULL || $row['cronograma'] != 'null') {
echo 'This is my reply';
}

If the field is actually NULL, the echo won't show up. If the field has the string null in it it does show up.

Please note that the fields in question are either NULL or has the "null" string without any spaces.

Aucun commentaire:

Enregistrer un commentaire