Simple If Statement for a blank field

I have an if state looking at the photo field and asking if empty to display nothing if there is something in the field display the else statement… I am missing something… Full Code below the statement

[embed=425,349]

if(empty($row[‘photo’]))
{
// it’s empty!
echo “”;
}
else
{
echo “<td class=“boxbg”> <a href=“http://www.website.com/admin/news/upload/”.$row[‘photo’].”" target="_blank" “><img src=“http://www.website.com/admin/news/upload/”.$row[‘photo’].”" width=“200” height=“200” align=“right” target="_blank">";

}

[/embed]

Full Code

[embed=425,349]<?php
ini_set (“display_errors”, “1”);
error_reporting(E_ALL);

$id = $_GET[‘id’];
$query = “SELECT * FROM news WHERE id = ‘$id’”;
$result = mysql_query($query);

while($row = mysql_fetch_array($result)) {
echo “

”.$row[‘title’]."

";

echo " <table width=“100%” border=“0” cellspacing=“0” cellpadding=“0”>


<td rowspan=“3” class=“boxarrow”>
<td class=“boxtopleft”>
<td class=“boxbg”><img src=“graphics/box-bg.png” alt=“240” width=“2” height=“2” />
<td width=“10” class=“boxtopright”>


<td class=“boxbg”>";
		  if(empty($row['photo']))

{
// it’s empty!
echo “”;
}
else
{
echo “<td class=“boxbg”> <a href=“http://www.website.com/admin/news/upload/”.$row[‘photo’].”" target="_blank" “><img src=“http://www.website.com/admin/news/upload/”.$row[‘photo’].”" width=“200” height=“200” align=“right” target="_blank">";

}

echo “”.$row[‘body’]."";
echo “”;

echo "<td class=“boxbg”>



<td class=“boxbottomleft”>
<td class=“boxbg”><img src=“graphics/box-bg.png” alt=“240” width=“2” height=“2” />
<td class=“boxbg”>

";

echo "

| Return to News |";
}
?>[/embed]

I don’t like messing around with " for it gets messy in my opinion, I like do this:

[php]echo isset($row[‘photo’]) ? ’

<a href=“http://www.website.com/admin/news/upload/”’ . $row[‘photo’] . ‘" target="_blank" "><img src=“http://www.website.com/admin/news/upload/”’ . $row[‘photo’] . ‘" width=“200” height=“200” align=“right” target="_blank">’ : NULL;[/php]

or

[php]echo isset($row[‘photo’]) ? ’

<a href=“http://www.website.com/admin/news/upload/”’ . $row[‘photo’] . ‘" target="_blank" "><img src=“http://www.website.com/admin/news/upload/”’ . $row[‘photo’] . ‘" width=“200” height=“200” align=“right” target="_blank">’ : " ";[/php]

Though I’m guessing you just want it blank, thus a NULL statement is just as good. :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service