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.

2
  • 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. Commented Aug 18, 2016 at 11:25
  • \"$row["pageLINK"]\" won't work, you either would need to do \"".$row["pageLINK"]."\" or \"{$row["pageLINK"]}\" Commented Aug 18, 2016 at 11:37

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This worked great and is super clean! Why don't you need any sort of quotes around the array index i.e. pageLINK ?
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 :)
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.

Comments

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

Try This

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.