Re: How to output a NULL field?
| From: | Shawn McKenzie | Date: | Tue, 25 Aug 2009 20:02:25 +0000 |
| Subject: | Re: How to output a NULL field? | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-297214@lists.php.net to get a copy of this message | ||
Shawn McKenzie wrote:
> First off, if the value is NULL in the database then in PHP it will be
> the string "NULL" and not a null value as far as I remember. Second,
> you cant use a function/method in empty(). Thirdly, the string "NULL"
> is not empty. I'm not sure what DB class you're using here or what the
> Fields() method actually returns. You should do a
> var_dump($rs->Fields(22)) to see. If it returns a string (especially
> "NULL"), then this or some variation should work:
>
> $q4 = $rs->Fields(22);
>
> if($q4 == "NULL"){
> $q4 = "";
> }
>
> If it returns an empty string or false then you may have nothing to do.
>
DOH! My bad. MySQL stores an empty value based upon the field type for
NULL. So if the field type is int then it sets it to 0 and if its
varchar, etc, it sets it to an empty string "". The MySQL functions
seem to return everything as a string, so for an int field it returns
the string "0", so:
$q4 = $rs->Fields(22);
if(empty($q4)){
$q4 = "";
}
But I'm not sure what benefit you get from this except that "0" is
changed to "".
--
Thanks!
-Shawn
http://www.spidean.com