I am trying to use is_null() for the first time to ensure I only display a result if the field in my table is not empty (using mySQL), but I can’t seem to get it to work properly.
My query is:
<?
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db) or die ("Unable to select database!");
$query = "SELECT * FROM dogs ";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{
?>
Then later in my page, I would print the results with:
Breed Name = <? echo $row->breed; ?>
What I would like to do is only have the breed name line show up if that field in the table has data. So, I tried:
<?
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db) or die ("Unable to select database!");
$query = "SELECT * FROM dogs ";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{
if ( is_null( . $row["breed "] . ) ) {
echo("<P>");
} else {
echo( . $row["breed "] . );
?>
I think I am close but this isn’t quite right. Any suggestions?
Thanks!!