Re: is_null question
| From: | Richard Lynch | Date: | Tue, 16 Jul 2002 03:49:45 +0000 |
| Subject: | Re: is_null question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-107787@lists.php.net to get a copy of this message | ||
>It looks like I should be using is_null(), but I'm not sure how to use it,
>especially since all of this is embedded in a print statement.
Disclaimer:
is_null() is new-fangled, and while I assume it matches up with SQL NULL,
it's *POSSIBLE* that PHP's NULL is for something entirely different than SQL
NULL. Read the docs.
>Instead of just printing Email: $row[1], I'd like to test whether it's null
>first--maybe something like this?
>
>if (is_null($row[1])) print " " else print ("Email: $row[0]")
>
>but can I put that line inside of another print statement? if so, do I have
>to escape the quotation marks? Please forgive my confusion--I'm new to
>programming in general and PHP in particular.
Several options are available.
In all cases, I've replaced the if/else with the trinary ? : operator. Less
clunky.
$email = is_null($row[0]) ? 'NULL' : $email;
# Didja know you could just hit TAB instead of that funky \t stuff? Way
prettier, IMNSHO.
print(" <tr><td>$email</td>...");
print(" <TR><TD>" . is_null($row[0]) ? 'NULL' : $email .
"</TD>";
#echo will take as many arguments as you like.
echo "<TR><TD>", is_null($row[0]) ? 'NULL' : $email,
"</TD>...";
--
Like Music? http://l-i-e.com/artists.htm