Search code examples
phphtmlmysqlechohref

PHP/HTML ~> href link from mysql fetch


Im trying to set up some text that links to the url column of the row for each item in the table. I tried the below which does not work at all and just gives me a white screen.

echo "<br><a href=\"$row["pageLINK"]\">". $row["pageNAME"]. "</a><br>";

But on the other hand, the code below works just fine.

echo "<br><a href=\"http://www.google.com\">". $row["pageNAME"]. "</a><br>";

It might be something very simple but I'm just getting into php so any kind of help would be appreciated.


Solution

  • You can't use quotes inside an echo when referencing an array index.

    This line:

    echo "<br><a href=\"$row["pageLINK"]\">". $row["pageNAME"]. "</a><br>";
    

    Should be this:

    echo "<br><a href='$row[pageLINK]'> $row[pageNAME]</a><br>";
    

    Or you could do using quotes and brackets, like in e4c5's answer.