How do I do this?

Hi Guys and gals,

I have a map page that pulls map pointers from and xml file.

The xml file is generated by a php script, pulling the data from a database.

How can I pass a variable to the php script that generates the xml, if I wanted to display different sets of map points?

One map might show the location of golf courses another airports.

Thanks

Will

Without seeing the code of the PHP file no one will be able to answer this. Do you have (access to) the PHP code? If so, could you share it with us?

BTW. Unless programmed explicitly in the PHP file, what you’re asking is not possible.

You could either post a variable with a form ( will not be seen ) or add it to the URL.

The benifit of the URL method is if somebody adds the page to favorites the variable will be saved in the URL. The form method is a neater URL but the page when visited again from the saved favorite will not display any information.

You then read the variable on the second page and use it in your MySql query.

Scallio,

I need to set some kind of variable so that the script that generates the map markers knows what data to pull.

Would $_SESSION variables wrok for this?

The map can be seen on www.costacalidanews.com

The google maps JS is held at www.costacalidanews.com/js/markers.js

This script generates the XML for the markers.


<?
echo '<?xml version="1.0"?>
<markers>
';

if ($_SERVER["SERVER_NAME"]=='localhost') {
echo "using local connection and config";
include "connect_local.inc.php"; 
include "config_local.inc.php"; 
}
else {
include "connect.inc.php"; 
include "config.inc.php"; 
}


$query = "SELECT * FROM map_marker WHERE  map_marker_live='1'";
$result = mysql_query($query);
while ($array = mysql_fetch_assoc($result)) {

$latlon = $array['map_marker_latlon'];


$pieces = explode(",", $latlon);
$lat = $pieces[0]; // piece1
$lon = $pieces[1]; // piece2


echo '
<marker>
<name>'.$array['map_marker_name'].'</name>
<address>'.$array['map_marker_text'].'</address>
<lat>'.$lat.'</lat>
<lng>'.$lon.'</lng>
<latlon>'.$lat.','.$lon.'</latlon>
</marker>
';

}

echo '</markers>';

?>


Rubble,

I’m not doing a post or a get to the script that generates the map points, since this is referenced in the JS, and not accessed directly.

I need to set some kind of variable on the server.

Thanks

Will

That scripts just pulls all the data points out of the database and shows them. But then, you already knew that :slight_smile:

What would you like achieve exactly? You said that you wanted to display different sets of map points; how are they different (i.e., what separates them from the others).

Also $_SESSION is (most likely, since I’m not 100% sure what you’re up to yet) not what you need here.

If the change is to be persistent just change the script, or if the script needs to react on a passed parameter (for example markers_xml.php?type=gasstation) use $_GET

The XML is parsed by javascript. The XML is generated by a separate script which is referenced in the javascript (markers_xml.php)

JS script:
www.costacalidanews.com/js/markers.js

XML:
www.costacalidanews.com/markers_xml.php

How can I pass a variable to markers_xml.php ??