1

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.

Co1eK
  • 15
  • 3
  • Any half-decent IDE would tell you why the code wont work and even if you want to go for a text editor rather than an IDE error reporting would also tell you the same. My suggestion: use both while developing. – apokryfos Aug 18 '16 at 11:25
  • `\"$row["pageLINK"]\"` won't work, you either would need to do `\"".$row["pageLINK"]."\"` or `\"{$row["pageLINK"]}\"` – CerebralFart Aug 18 '16 at 11:37

3 Answers3

1

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.

Community
  • 1
  • 1
Phiter
  • 14,570
  • 14
  • 50
  • 84
  • This worked great and is super clean! Why don't you need any sort of quotes around the array index i.e. pageLINK ? – Co1eK Aug 18 '16 at 11:25
  • It's a PHP rule. Quotes inside a quotted string will close the string if they are not escaped. Your problem could have been solved in many different ways, but this one is the easiest and most common. If you got a blank page, it means you probably have your error reporting turned off. If they were turned on you would have seen the problem right away. [Turn them on](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) :) – Phiter Aug 18 '16 at 11:28
1

First of all you must need to on PHP Error Reporting on development line like:

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

You have syntax error in your code, solution:

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

Side Note: PHP Error Reporting will display all errors instead of blank page.

devpro
  • 16,184
  • 3
  • 27
  • 38
0
echo '<br><a href="'.$row["pageLINK"].'">'. $row["pageNAME"]. '</a><br>';

Try This

Hitesh Aghara
  • 186
  • 1
  • 9