alexmark Posted July 25, 2012 Share Posted July 25, 2012 Hi all I am trying to echo a google map url from a db. The problem is when I echo it it adds teh websites url back on to the front of the map url. eg. In the db is stored http://maps.google.com/maps? which is correct. when I echo it out I get http://american-auto-exchange.com/%3Cp%3Ehttp://maps.google.com/maps? Can some one please tell me where I am going wrong with the code below please. Thank you in advance for giving up your time to help newbies like me. <h1>Location Map</h1> <p class="indent"> <a href="<?php $result = mysql_query("SELECT * FROM site_settings") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo "<p>".$row['mapurl']."</p>"; } ?>" target="_blank" title="Click here for a location map">Click here for a location map</a></p> Quote Link to comment https://forums.phpfreaks.com/topic/266228-url-error/ Share on other sites More sharing options...
DavidAM Posted July 25, 2012 Share Posted July 25, 2012 <a href="<?php $result = mysql_query("SELECT * FROM site_settings") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo "<p>".$row['mapurl']."</p>"; } ?>" target="_blank" title="Click here for a location map">Click here for a location map</a></p> This is one of the reasons we separate our application logic from the presentation logic. You are in the middle of an HTML Anchor tag HREF attribute and you are putting PARAGRAPH tags inside it (the HREF attribute). // Get map URL $result = mysql_query("SELECT * FROM site_settings") or die(mysql_error()); $row = mysql_fetch_array($result); $mapUrl = $row['mapurl']; # ... // output the link ?> <h1>Location Map</h1> <p class="indent"> <a href="<?php echo $mapUrl;?>" target="_blank" title="Click here for a location map">Click here for a location map</a></p> Disclaimer: I just rearranged the OP's code. I do not recommend "or die()"; but I do recommend testing to see if the query succeeded. Quote Link to comment https://forums.phpfreaks.com/topic/266228-url-error/#findComment-1364286 Share on other sites More sharing options...
alexmark Posted July 25, 2012 Author Share Posted July 25, 2012 Thank you so much for the help and lesson. I had never really thought about the separation before but as you explained it it does make complete sense. So as I understand from what you have said you always call the information as it were out side and then display the results within the <p> class etc. Which would make all the css work correctly as it does now because I was having problems with that also. You are a star and once again thank you so very much. Quote Link to comment https://forums.phpfreaks.com/topic/266228-url-error/#findComment-1364289 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.