Jump to content

rawurlencode() displaying mySQL results %20, screws up on spaces


respecttheplayer

Recommended Posts

http://www.thegreatestsave.org/events.php

 

Above is my page that I am having some issues, below address you will see "click here for directions".

 

The issue is when displaying results that have a space in the url it does not properly encode the %20 that mapquest would like instead it only displays something like this "http://www.mapquest.com?state=FL&city=Palm"

 

However the correct URL that was inserted into a database is: http://www.mapquest.com?state=FL&city=Palm Beach&address="

 

Mapquest reads URLS by converting all spaces to %20 so it would be converted to http://www.mapquest.com?state=FL&city=Palm%20Beach&address=" 

 

I was then told to use a rawurlencode() but I am not sure how to properly use this. Below is my code how i tried to do it but it did not work. (also let me know if i am even going about this the right way)

	 echo ' 

						 <tr bgcolor="' . $row_color . '"> 

						  <td><p class=info>' .$results['Date'] . '</p></td> 

						  <td><p class=info><a href=' .$results['link'] . ' target=\"blank\">' .$results['City'] . '</a></p></td> 

						  <td><p class=info><b>' .$results['Event'] . ' </b><br><a href=' .$results[rawurlencode('mapquest')] . ' target=\"blank\">click for directions</a></p></td>


						  <td><p class=info>' .$results['Media'] . '  ' . $results['Sponsor'] . '</p></td>

						  <td><p class=info>' .$results['Time'] . '</p></td>

						  </tr>'; 



						 // Increment the row count 

						 $row_count++; 

 

 

 

 

That does not explain why the other URL's in a different field work with out double quotes;

  <td><p class=info><a href=' .$results['link'] . ' target=\"blank\">' .$results['City'] . '</a></p></td> 

In that instance I am pulling simple URLS like http://www.thegreatestsave.org/wusa-tgs/index.php.

 

However win I pull mapquest nothing works and it doubles the URL, it shows http://www.thegreatestsave.org/%22/http://www.mapquest.com/....... which makes no sense, i just want it to show mapquest URL any ideas?

 

 

I just noticed this:

<td><p class=info><b>' .$results['Event'] . ' </b><br> ' .$results['mapquest'] . ' click for directions</a></p></td>

 

when i do that it displays perfectly which is not WITHIN the Anchor tag <a href=...... but once i add this :

<td><p class=info><b>' .$results['Event'] . ' </b><br><a href= ' .$results['mapquest'] . '> click for directions</a></p></td>

 

Ive also tried it like this :

<td><p class=info><b>' .$results['Event'] . ' </b><br><a href=\" ' .$results['mapquest'] . '\"> click for directions</a></p></td>

it screws up! any ideas

I will keep this open in case someone figures something out later, but I did the tedious work and just added %20 into all the space in the database field "mapquest" I know that it can work with out it, i just need to figure it out or be directed correctly.

 

Thanks again for input

Bro, you HAVE to put double quotes around HTML attributes.  If you don't, that isn't HTML, it's some bastardized version.

 

Without the double quotes, anytime there is a space in the URL, the rest of the URL is going to be truncated, so:

 

<a href=http://www.example.com/?test=This is a test>TEST</a>

 

Is going to link to: http://www.example.com/?test=This

 

You need to properly format your HTML or you can never expect it to work consistently.

 

<?php
echo '
<tr bgcolor="' . $row_color . '">
<td>
	<p class=info>' .$results['Date'] . '</p>
</td>
<td>
	<p class=info>
		<a href="'.$results['link'].'" target="blank">'.$results['City'].'</a>
	</p>
</td>
<td>
	<p class=info>
		<b>'.$results['Event'].'</b><br />
		<a href="'.$results[rawurlencode('mapquest')].'" target="blank">click for directions</a>
	</p>
</td>
<td>
	<p class=info>'.$results['Media'].'  '.$results['Sponsor'].'</p>
</td>
<td>
	<p class=info>'.$results['Time'].'</p>
</td>
</tr>';
?>

Archived

This topic is now archived and is closed to further replies.

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