2011-11-27 56 views

回答

1
<?php 
    if(isset($row['link']) && !empty($row['link'])) 
    { 
     echo '<td><a href="'.$row['link'].'" target="_self\">Link</a></td>'; 
    } else { 
     echo '<td>Link</td>'; 
    } 
?> 
+0

是啊,但现在有一个问题,我还需要文字链接到显示不完全去除。这个想法就是当数据超链接被创建时,如果不仅仅是正常的文本链接将被显示 – buni

+0

@ user12345678只是添加一个'else'子句,你很好去? – Nasreddine

1

不知道你的表的结构,这是不能说这是否会工作,但它是一个良好的开端:

<?php if(strlen($row['link']) > 0):?> 
<td><?php echo "<a href=\"".$row['link']."\" target=\"_self\">Link</a>"; ?></td> 
<?php endif; ?> 
0

做一个isset和修剪+ strlen的检查0周围的数据,然后将链接标题包装在锚标签中。

$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