MrsVodes Posted March 20, 2019 Share Posted March 20, 2019 So this is the code prior to trying to add a hyperlink echo "<p>Name: " . $item["first_name"] . " " . $item["last_name"] . "<br> Email: " . $item ["email"] . "</p>"; I thought that putting the <a href around the $item['email'] would make the email address a hyperlink but it does not ... it skips the email addresses completely and hyperlinks the names because all fields are $item. echo "<p>Name: " . $item["first_name"] . " " . $item["last_name"] . "<br> Email: " . "<a href=\"mailto: {$item ["email"]} \">" . "</p>"; Thank you for any assistance. Quote Link to comment Share on other sites More sharing options...
benanamen Posted March 20, 2019 Share Posted March 20, 2019 (edited) First off, I would suggest eliminating all the escaping gymnastics. It is harder to read, more prone to error and not as clean as not doing it. As to your problem, you are missing the basic syntax of a hyperlink, the closing </a>. Here is a cleaned up version. Take note of the single quotes on the elements. echo "<p>Name:{$item['first_name']} {$item['last_name']}<br> Email: <a href='mailto: {$item['email']}'>{$item['email']}</a></p>"; Edited March 20, 2019 by benanamen Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 20, 2019 Share Posted March 20, 2019 While Benanamen's re-write is a better approach I thought I could help you understand the original problem with this tid bit. The reason your email address 'disappeared' is because when you built the anchor tag around it, you left out the anchor tag piece that shows you "the link" literal. That's the part that Benanamen added during his re-write of your code, between the <a......> and the </a>. Another good way (IMHO) of writing this code is to use heredocs construct which is great for outputting a lot of html and php code that is mixed in. $code= <<<heredocs <p> Name: $item['first_name'] $item['last_name'] <br> Email: <a href="mailto:$item['email']">$item['email']</a> </p> heredocs echo $code; For more in the PHP manual on using 'heredocs' go HERE Quote Link to comment Share on other sites More sharing options...
MrsVodes Posted March 20, 2019 Author Share Posted March 20, 2019 Thank you both for your assistance. I am unable to get either of the responses to work. It hits a page not working error on the first and has a formatting error in the second so I did not try to upload to URL. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 20, 2019 Share Posted March 20, 2019 Show us what you changed to match us. Do you have error checking turned on and have an error message that points to a certain line? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 20, 2019 Share Posted March 20, 2019 oops - I see that I left the semi off my ending heredocs line. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 20, 2019 Share Posted March 20, 2019 Nobody noticed, honest! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.