dealing with MySQL NULL's

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

dealing with MySQL NULL's

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: dealing with MySQL NULL's

Post by Weirdan »

is_null() is a function, so you should use it like this:

Code: Select all

if (is_null($value)) {
  // do something
}
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Re: dealing with MySQL NULL's

Post by IGGt »

that makes sense, why I didn't spot that I don't know.
cheers
Post Reply