Re: Checking for Null Variables

From: Date: Fri, 07 Mar 2003 17:33:27 +0000
Subject: Re: Checking for Null Variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-138666@lists.php.net to get a copy of this message
you can look at isset() and empty(). If you retrieve the query result with Mysql association (ie. $field=mysql_fetch_array($resource, MYSQL_ASSOC), then even the field has a blank value, there will be a blank variable created ($field["Name"] is created but with no value)), however if you grab the resource values as such $field=mysql_fetch_array($resource), then a blank field will not create a $field["Name"]. So, if using : $field=mysql_fetch_array($resource, MYSQL_ASSOC) if(empty($field["Name"])) { do this } else { do this } OR $field=mysql_fetch_array($resource) if(!isset($field["Name"])) { do this } else { do this } "Christopher J. Crane" <ccrane@ikon.com> wrote in message news:20030307172509.20625.qmail@pb1.pair.com... > How do I check if a variable is blank or not. I am returning data from a > MySQL database and if a field is empty I would like to do something > different. > > I tried > if($field["Name"] == "") { do this } > else { do this } > > It does not work right. Actually, at one point, it was working in the exact > opposite manner. > >

« previous php.general (#138666) next »