Main image
20th March
2011
written by admin

The PHP files

The following two files need to be uploaded to your root folder. We will give you the code (courtesy of Google) and explain what you need to change.

phpsqlajax_dbinfo.php

This file allows your map code to access your database.

$username="your db username";
$password="your db password";
$database="your db name";
?>

Should be easy to figure out what you have to do here.

 

phpsqlajax_genxml.php

This is the secondary file, and we have already in the first stage identified where you ”call” to this file.

require("phpsqlajax_dbinfo.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr); $xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can't use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM map WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '
echo 'posttitle="' . parseToXML($row['posttitle']) . '" ';
echo 'url="' . $row['url'] . '" ';
echo 'gpaddress1="' . $row['gpaddress1'] . '" ';
echo 'gpaddress2="' . $row['gpaddress2'] . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'gptel="' . parseToXML($row['gptel']) . '" ';
echo 'gpahtel="' . parseToXML($row['gpahtel']) . '" ';

echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo '/>';
}
// End XML file
echo '';
?>

We have used bold to higlight the fields in this file you have to change to suit your map. Firstly, if you have changed the first php file name, change it. Secondly, change the databse fields to correlate with your own database field names. It is worth mentioning here that address in our databse reflects the UK post code, used in this map for the geocoding aspect.



STEP 3: We will deal here with setting up your database.

Leave a Reply