Page 1 of 1

dealing with MySQL NULL's

Posted: Wed Jul 21, 2010 11:25 am
by IGGt
I have a script that passes data from a MySQL query into a <Table>, but periodically some of the MySQL rows contain NULL values. When put in the Table they appear as blank spaces, so I thought if I could test for them I could replace them with a &nbsp in order to create a valid <td> entry.

But so far all I am getting is a parse error.

What I came up with is:

Code: Select all

foreach ($row as $attribute)
	if ( $attribute is_null )
	{ 	print "<td>&nbsp" ;
	        print "\n";
	        print "<br/></td>";
	} else {
 	        print "<td>{$attribute} " ;
	        print "\n";
	        print "<br/></td>";
	}
but it doesn't work. Is there a way of making this work?

Re: dealing with MySQL NULL's

Posted: Wed Jul 21, 2010 11:38 am
by Weirdan
is_null() is a function, so you should use it like this:

Code: Select all

if (is_null($value)) {
  // do something
}

Re: dealing with MySQL NULL's

Posted: Thu Jul 22, 2010 3:28 am
by IGGt
that makes sense, why I didn't spot that I don't know.
cheers