1

I am trying to concatenate retrieved data from the database into a table cell and make the URL clickable.

I am using the tag with the an href attribute to achieve that, but for some reason it is not working and I'm presented with a blank table cell. Any idea why?

echo "<tr>" . 
         "<td>" . $historyData['Name'] . "</td>" . 
         "<td><a href=\"" . $historyData['URL'] . "\"/a></td>" .
      "</tr>";

Also tried

echo "<tr>" . 
          "<td>" . $historyData['Name'] . "</td>" . 
          "<td><a href="" . $historyData['URL'] . ""/a></td>" .
      "</tr>";

Thanks in advance.

1
  • 1
    I really, really would suggest to stop using capitalized letters in array indexes. Commented Nov 17, 2016 at 0:42

1 Answer 1

1

You have an option to make a string with ' and ".

if(isset($historyData['Name']) && isset($historyData['URL'])){
  echo "<tr>" . 
         "<td>" . $historyData['Name'] . "</td>" . 
         '<td><a href="' . $historyData['URL'] . '">title</a></td>' .
       "</tr>";
} else {
  echo 'Whoops, I made a booboo with my indexes..';
  print_r($historyData);
}

Then there is also the option of doing something like this:

echo "<td><a href='{$historyData['URL']}'>title</a></td>";

Note that you require to use the not literal string, "

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

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.