Hi, the below code and SQL query are the contents of an XML template, listing a location marker for each member of our site , which then gets plotted on a member map.
For some reason this code acts very strange. a) Sometimes the sql file will output kinda properly, but only list about 60 or so members (when our site has 300+) and it lists these 60 in a weird way, eg. jumping from member id 36 to 57 etc. b) A lot of times it will only output the top <markers> tag and nothing else. c) Most ofthen though, it outputs just the first 6 or 7 users and does not inlclude the closing </markers> tag.
Any help would be much appreciated! This file is driving me crazy.
<markers>
<?php
// My Google Maps API key where X's are
$key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
global $DB;
$query = "SELECT m.member_id, m.screen_name, m.photo_filename, c.m_field_id_3 AS postcode FROM exp_members m LEFT JOIN exp_member_data c ON m.member_id=c.member_id";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$postcode = $row['postcode'];
$postcode = urlencode("$postcode");
$postcode = substr($postcode,0,(strlen($postcode)-1));
// Desired address
$url = "http://maps.google.com/maps/geo?q=$postcode&output=xml&key;=$key";
// Retrieve the URL contents
$page = file_get_contents($url);
// Parse the returned XML file
$xml = new SimpleXMLElement($page);
// Check for error
list($code) = explode(",", $xml->Response->Status->code);
if ($code == "200")
{
// Parse the coordinate string
list($longitude, $latitude, $altitude) = explode(",", $xml->Response->Placemark->Point->coordinates);
// Output the coordinates
echo "<marker ";
echo "lat=\"$latitude\" lng=\"$longitude\" name=\"";
echo $row['screen_name'];
echo "\" photo=\"";
echo $row['photo_filename'];
echo "\" memid=\"";
echo $row['member_id'];
echo "\" >";
}
}
?>
</markers>