Jump to content
xisto Community
Sign in to follow this  
BuffaloHelp

Quick Example On Passing Query And # Targeting Within One Page

Recommended Posts

In PHP using $_GET allows to grab variable from URL and use it effectively such as in dynamic content style.

 

Suppose you want to use $_GET to set the situation but instead of pop up window for additional information, target to the location and shift the viewer to the right place, i.e. herf=domain#target_id?

 

Let's say we have a simple list of directions using Google maps. The list "UL" and "LI" shows different locations. And instead of opening Google map to a new window, you are going to embed Google map to the bottom of the same page. But perhaps it would be best to draw the attention to the newly included map by using # targeting method.

 

File no.1 is for listing locations and links for map direction

 

<ul>
<li><a href="?direction=1#map">New York</a></li>
<li><a href="?direction=2#map">Florida</a></li>
<li><a href="?direction=3#map">California</a></li>
</ul>
<div style="height:400px;">
<!--this is to create distance between above list and below map. Mainly to demonstrate the # target effect-->
</div>
<?PHP
if ($_GET['direction'] == "1"){
print '<div id="map">'; 
print '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=new+york&sll=37.0625,-95.677068&sspn=33.489543,55.898438&ie=UTF8&ll=41.008921,-73.852844&spn=0.999718,1.746826&z=9&iwloc=A&output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&source=embed&hl=en&geocode=&q=new+york&sll=37.0625,-95.677068&sspn=33.489543,55.898438&ie=UTF8&ll=41.008921,-73.852844&spn=0.999718,1.746826&z=9&iwloc=A" style="color:#0000FF;text-align:left">View Larger Map</a></small>';
print '</div>';
}
elseif ($_GET['direction'] == "2"){
print '<div id="map">'; 
print '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=florida&sll=40.822124,-73.987427&sspn=0.999718,1.746826&ie=UTF8&ll=30.012031,-80.441895&spn=8.816277,13.974609&z=6&iwloc=A&output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&source=embed&hl=en&geocode=&q=florida&sll=40.822124,-73.987427&sspn=0.999718,1.746826&ie=UTF8&ll=30.012031,-80.441895&spn=8.816277,13.974609&z=6&iwloc=A" style="color:#0000FF;text-align:left">View Larger Map</a></small>';
print '</div>';
}
elseif ($_GET['direction'] == "3"){
print '<div id="map">'; 
print '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=california&sll=28.516969,-81.518555&sspn=8.816277,13.974609&ie=UTF8&ll=40.946714,-117.246094&spn=16.653748,27.949219&z=5&iwloc=A&output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&source=embed&hl=en&geocode=&q=california&sll=28.516969,-81.518555&sspn=8.816277,13.974609&ie=UTF8&ll=40.946714,-117.246094&spn=16.653748,27.949219&z=5&iwloc=A" style="color:#0000FF;text-align:left">View Larger Map</a></small>';
print '</div>';
}
else {
print '<div id="map">';
//do something else
print '</div>';
}
?>

 

Save the above as filename.php and give it a go.

 

To further discuss, you can see the familiar

 

<a href="?direction=1#map">

 

which is the combination of index.php?direction=1 and index.php#map. When used together to manipulate a web page for ease of focusing on the newly embedded content this certainly is the quickest way to perform much desired function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.