Re: Checking for Null Variables

From: Date: Fri, 07 Mar 2003 18:37:02 +0000
Subject: Re: Checking for Null Variables
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-138675@lists.php.net to get a copy of this message
isset is the function I was looking for. I could not remember what it was. Thank you. "Bobby Patel" <anup_patel@rogers.com> wrote in message news:20030307173341.28452.qmail@pb1.pair.com... > 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 (#138675) next »