CASE: NULL [SOLVED]
Posted: Tue May 02, 2006 2:11 pm
I have a boolean field in my database. Based on the value of the field (NULL/0/1), I want to take different actions. I use a switch, like so:
Unfortunately, it seems that a DB value of NULL is not being converted to PHP's NULL, and is instead matching the 0 case. This means I can't replace my case NULL with a plain default either - NULL will still trip the case 0. I checked the pg_fetch_array documentation, and it said that it is supposed to be properly preserving NULL values.
Am I overlooking something, or can I not use a switch?
Edit: I tried explicitly setting $var = NULL and switching on it, and it still equated 0 with NULL, regardless of the order of the case statements.
Code: Select all
switch($boolean)
case 0: /* do something for records that have been assigned a 0 value */ break;
case 1: /* do something for records that have been assigned a 1 value */ break;
case NULL: /* do something for records that have not been assigned a value yet */ break;Am I overlooking something, or can I not use a switch?
Edit: I tried explicitly setting $var = NULL and switching on it, and it still equated 0 with NULL, regardless of the order of the case statements.