1

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.

1
  • 1
    your stored urls looks like: http://... or <a href="http://.."... ? Commented Aug 10, 2014 at 18:43

2 Answers 2

1

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 } ?>
Sign up to request clarification or add additional context in comments.

1 Comment

This worked. My urls are all stored without the http:// All I had to was add that to the <a href=" and it works perfectly. Thanks for your quick response!
0
<?php
  $weblink = $row_rsEvents['weblink'];  
  if($weblink != '') { 
    echo "<span class=\"webAddress\"><a href=\"$weblink\">$weblink</a></span><br>";
  } 
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.