How to put a hyperlink in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Paradox187x
Forum Newbie
Posts: 7
Joined: Mon Jul 20, 2009 6:24 am

How to put a hyperlink in PHP

Post by Paradox187x »

Sorry if this has already been brought up (couldn't find an answer anywhere). :roll:

I want to show a result obtained from a database within php, as a link, but the following line doesn't work.

NOTE: the result provided by {$row['LISTEN']} is an address, eg, "www.test.com/hello.html"

Code: Select all

echo " <td><a href="{$row['LISTEN']}" target="_blank">LINK</a></td>\n";
I can't get this method to work either.

Code: Select all

      $link = {$row['LISTEN']}
      echo " <td><a href="{$link}"LINK</a></td>\n";
How is a HTML hyperlink created within PHP code
Last edited by Benjamin on Mon Jul 20, 2009 6:46 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: How to put a hyperlink in PHP

Post by jackpf »

How does that not work??
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How to put a hyperlink in PHP

Post by Benjamin »

Randwulf
Forum Commoner
Posts: 63
Joined: Wed Jan 07, 2009 7:07 am

Re: How to put a hyperlink in PHP

Post by Randwulf »

In the first one you're ending the string prematurely. When PHP reads a string, it starts at the single/double quotes and goes until it sees another single/double quote.

So echo " <td><a href="{$row['LISTEN']}" target="_blank">LINK</a></td>\n";

Is read as echo " <td><a href=" and then some invalid syntax. To fix this, use only single quotes within the two end double quotes, or you can use the <<< syntax if you're feeling spiffy.

In the second one, you forgot to end the line with a semicolon and you did the same thing as you did in the first one. Don't you have error reporting on in PHP.ini? That would make this stuff easy to catch.
Last edited by Randwulf on Mon Jul 20, 2009 11:59 am, edited 1 time in total.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: How to put a hyperlink in PHP

Post by jackpf »

Oh hey I didn't even notice he wasn't using single quotes....
Paradox187x
Forum Newbie
Posts: 7
Joined: Mon Jul 20, 2009 6:24 am

Re: How to put a hyperlink in PHP

Post by Paradox187x »

Thanx Randwulf

Just started php writing & well any form of programming last week, so I sometimes miss the painfully obvious.

Thanx a heap.
Post Reply