Jump to content

URL Error


alexmark

Recommended Posts

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> 

Link to comment
Share on other sites

<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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.