Hi,
I have a bit of code for retrieving records about paintings that works great:
$query = 'SELECT * FROM items, artists WHERE items.artist_id = artists.id';
if ($r = mysql_query ($query)) {
while ($row = mysql_fetch_array ($r)) {
$low_estimate = number_format($row['low_estimate']);
$high_estimate = number_format($row['high_estimate']);
print "<tr><td></td><td>\n
{$row['first_name']} {$row['last_name']}<br />
{$row['nationality']} {$row['lifespan']}<br />{$row['title']}<br />
{$row['medium']}<br />
{$row['dimensions']}<br />
\$$low_estimate/$high_estimate</td></tr>\n
<tr><td colspan=\"2\"><hr /></td><td></td></tr>";
}
} else {
die ('<p>Could not retrieve the data because: <strong>' . mysql_error() . "</strong>. The query was $query.</p>");
}
mysql_close();
The thing is, I'd like to set each of the rows of text (not referring here to table rows in MySQL but lines of resulting HTML) to not display if the field is empty, so I went to do something like this for each:
if (is_empty ({$row['dimensions']})) then print "" else print "{$row['dimensions']}"<br />;
But it doesn't work because my syntax is off. Can anybody assist a helpless village idiot here? Thanks.
EDIT: I figured it out. Here's the revised code:
$query = 'SELECT * FROM items, artists WHERE items.artist_id = artists.id';
if ($r = mysql_query ($query)) {
while ($row = mysql_fetch_array ($r)) {
$low_estimate = number_format($row['low_estimate']);
$high_estimate = number_format($row['high_estimate']);
print "<tr><td></td><td>\n
{$row['first_name']} {$row['last_name']}<br />
{$row['nationality']} {$row['lifespan']}<br />{$row['title']}<br />";
if (!empty($row['medium'])) { print "{$row['medium']}<br />"; }
if (!empty($row['dimensions'])) { print "{$row['dimensions']}<br />"; }
print "\$$low_estimate/$high_estimate</td></tr>\n
<tr><td colspan=\"2\"><hr /></td><td></td></tr>";
}
} else {
die ('<p>Could not retrieve the data because: <strong>' . mysql_error() . "</strong>. The query was $query.</p>");
}
mysql_close();
?>
I figured out how to negate the function empty to !empty (not empty). That did it.