[PHP] Re: Checking for Null Variables

2003-03-07 Thread Bobby Patel
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 [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 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.





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Checking for Null Variables

2003-03-07 Thread Christopher J. Crane
isset is the function I was looking for. I could not remember what it was.
Thank you.
Bobby Patel [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 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 [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  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.
 
 





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php