Page 1 of 1

How to put a hyperlink in PHP

Posted: Mon Jul 20, 2009 6:41 am
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

Re: How to put a hyperlink in PHP

Posted: Mon Jul 20, 2009 6:42 am
by jackpf
How does that not work??

Re: How to put a hyperlink in PHP

Posted: Mon Jul 20, 2009 6:47 am
by Benjamin

Re: How to put a hyperlink in PHP

Posted: Mon Jul 20, 2009 10:07 am
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.

Re: How to put a hyperlink in PHP

Posted: Mon Jul 20, 2009 10:18 am
by jackpf
Oh hey I didn't even notice he wasn't using single quotes....

Re: How to put a hyperlink in PHP

Posted: Tue Jul 21, 2009 6:01 am
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.