Reputation: 662
<td><?php echo "<a href=\"".$row['link']."\" target=\"_self\">Link</a>"; ?></td>
I would like the Link to be hyper-linked only if there is a data['link']in MySQL table
Any idea?
Upvotes: 3
Views: 400
Reputation: 37838
<?php
if(isset($row['link']) && !empty($row['link']))
{
echo '<td><a href="'.$row['link'].'" target="_self\">Link</a></td>';
} else {
echo '<td>Link</td>';
}
?>
Upvotes: 1
Reputation: 1104
Do an isset and trim + strlen check of 0 around the data, before wrapping the Link caption in an anchor tag.
$linkHtml = "Bloopdie";
// Add anchor tag only if there is data in the row
if (isset($row['data']) && strlen(trim($row['data'])) > 0) {
$linkHtml = '<a href="' . $row['data'] . '">' . $linkHtml . '</a>';
}
echo $linkHtml
Upvotes: 0
Reputation: 10583
Without knowing the structure of your table, it's not possible to say if this will work, but it is a good start:
<?php if(strlen($row['link']) > 0):?>
<td><?php echo "<a href=\"".$row['link']."\" target=\"_self\">Link</a>"; ?></td>
<?php endif; ?>
Upvotes: 1