[thelist] is_null php

Simon Willison cs1spw at bath.ac.uk
Tue Jul 29 19:27:01 CDT 2003

Hi Tom,

Tuesday, July 29, 2003, 11:54:18 PM, you wrote:
> I have a NULL date value in my mySQL table. I want to test and see
> whether it has a date or its null, a simple if condition. If it is
> not null, i want to print out a variable.

> For some reason I can't get it to work. I tried:

> <? if (!is_null($eDateEnd))
>   to <?=$eDateEnd?>
> <?}?>

> What am I doing wrong?

is_null checks for PHP's bult in null type, but a NULL in a MySQL
database is handed over to PHP as an empty string (the type
information doesn't make it across). Instead you can do this:

select *, somefield is null as isnull from tablename ...

Then you'll get a variable returned to PHP called 'isnull' which
will be 1 if somefield is null and 0 otherwise. You can use "is not
null" in a similar fashion.

Hope that helps,


More information about the thelist mailing list