user2930069
user2930069

Reputation: 49

php database field as hyperlink

I have a mySQL database that has a web address field that is a type: text. When it shows up on my web page I would like it to be clickable as a hyperlink.

I have code around the field to "show if not empty" and can't figure out how to wrap it as a hyperlink.

Here's my code:

<?php if($row_rsEvents['weblink'] != "") { ?><span class="webAddress"><?php echo $row_rsEvents['weblink']; ?></a></span><br><?php } ?>

Thanks for your help.

Upvotes: 1

Views: 863

Answers (2)

Mureinik
Mureinik

Reputation: 311143

<?php
  $weblink = $row_rsEvents['weblink'];  
  if($weblink != '') { 
    echo "<span class=\"webAddress\"><a href=\"$weblink\">$weblink</a></span><br>";
  } 
?>

Upvotes: 0

Erlesand
Erlesand

Reputation: 1535

You need to add an <a> after your opening <span>,

<?php 
if($row_rsEvents['weblink'] != "") { ?>
    <span class="webAddress"><a href="<?php echo $row_rsEvents['weblink']; ?>"><?php echo $row_rsEvents['weblink']; ?></a></span><br>
<?php } ?>

Upvotes: 1

Related Questions