I suspect the problem comes from your creating a XML document, and specifying headers for it after content has been created. Might I suggest you drop the XML stuff until the very end if you really need it, and instead fill an array with your results returned from SQL, then use the array to create your output format: this could be JSON or XML or something else you may require. Something like this:
[code]<?php
require("connect.php");
// Get parameters from URL - these should be cleaned before use here!!!
// Example: $center_lat = MyCleaningFunction($_GET["lat"]);
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];
// 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());
}
// Search the rows in the markers table
$query = sprintf("SELECT id, name, address, lat, lng, ( 3959 * acos( cos(
radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) -
radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS
distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0, 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// Iterate through the rows, adding to array for each
$retVal = array();
while ($row = @mysql_fetch_assoc($result)){
$retVal[] = array( "id" => $row['id'],
"name" => $row['name'],
"address" => $row['address'],
"lat" => $row['lat'],
"lng" => $row['lng'],
"distance" => $row['distance'] );
}
// Return as JSON
$json = json_encode($retVal);
return $json;
// Return as XML...
// Refer to e.g.
http://stackoverflow.com/questions/1397036/how-to-convert-array-to-simplexml // for various ways to do this. No need to create a new document with headers, etc....
$xml = MyArrayToXMLConverter($retVal);
?>[/code]
HTH, Rob