$query = "SELECT *,
(((acos(sin((".$latitude."*pi()/180)) * sin((`lat`*pi()/180))
+cos((".$latitude."*pi()/180)) * cos((`lat`*pi()/180))
* cos(((".$longitude."- `lng`)*pi()/180))))*180/pi())*60*1.1515)
as distance
FROM `markers`
ORDER BY distance ASC
LIMIT 0,50
";
$stores = $this->db->executeQuery($query);
$stores = $stores['result'];
return $stores;SELECT distinct
sc.pagetitle ,
sc.content ,
(((acos(sin((".$latitude."*pi()/180)) * sin((lat_tvcv.`value`*pi()/180))
+cos((".$latitude."*pi()/180)) * cos((lat_tvcv.`value`*pi()/180))
* cos(((".$longitude."- lng_tvcv.`value`)*pi()/180))))*180/pi())*60*1.1515)
as distance
FROM (
`modx_site_content` AS sc,
`modx_site_tmplvars` AS lat_tv ,
`modx_site_tmplvars` AS lng_tv)
LEFT JOIN `modx_site_tmplvar_contentvalues` AS lat_tvcv
ON lat_tvcv.contentid = sc.id AND lat_tvcv.tmplvarid = lat_tv.id
LEFT JOIN `modx_site_tmplvar_contentvalues` AS lng_tvcv
ON lng_tvcv.contentid = sc.id AND lng_tvcv.tmplvarid = lng_tv.id
WHERE sc.`parent` IN (".$parent.") AND sc.`published`= '1' AND sc.`deleted`= '0'
AND lat_tv.name = 'lat'
AND lng_tv.name = 'lng'
ORDER BY distance ASC
LIMIT 0,50Parse error: syntax error, unexpected T_LNUMBER in /var/www/web/manager/includes/document.parser.class.inc.php(770) : eval()'d code on line 309
WHERE sc.`parent` IN (".$parent.") AND sc.`published`= "1" AND sc.`deleted`= "0"
WHERE sc.`parent` IN (".$parent.") AND sc.`published`= "1" AND sc.`deleted`= "0"
WHERE sc.`parent` IN (".$parent.") AND sc.`published`= '1' AND sc.`deleted`= '0'Error in query: SELECT distinct sc.pagetitle , sc.content , (((acos(sin((51.4926591*pi()/180)) * sin((`lat_tvcv.value`*pi()/180)) +cos((51.4926591*pi()/180)) * cos((`lat_tvcv.value`*pi()/180)) * cos(((-0.0542387- `lng_tvcv.value`)*pi()/180))))*180/pi())*60*1.1515) as distance FROM ( `modx_site_content` AS sc, `modx_site_tmplvars` AS lat_tv , `modx_site_tmplvars` AS lng_tv) LEFT JOIN `modx_site_tmplvar_contentvalues` AS lat_tvcv ON lat_tvcv.contentid = sc.id AND lat_tvcv.tmplvarid = lat_tv.id LEFT JOIN `modx_site_tmplvar_contentvalues` AS lng_tvcv ON lng_tvcv.contentid = sc.id AND lng_tvcv.tmplvarid = lng_tv.id WHERE sc.`parent` IN () AND sc.`published`= '1' AND sc.`deleted`= '0' AND lat_tv.name = 'latitude' AND lng_tv.name = 'longitude' ORDER BY distance ASC LIMIT 0,50 . You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND sc.`published`= '1' AND sc.`deleted`= '0' AND lat_tv.name = 'latitude' ' at line 16
lat_tv.name = 'latitude'
lng_tv.name = 'longitude'
(((acos(sin((51.4926591*pi()/180)) * sin((lat_tvcv.value*pi()/180)) +cos((51.4926591*pi()/180)) * cos((lat_tvcv.value*pi()/180)) * cos(((-0.0542387- lng_tvcv.value)*pi()/180))))*180/pi())*60*1.1515)
SELECT distinct sc.pagetitle , sc.content , sc.id, (((acos(sin((360*pi()/180)) * sin((lat_tvcv.`value`*pi()/180)) +cos((360*pi()/180)) * cos((lat_tvcv.`value`*pi()/180)) * cos(((30- lng_tvcv.`value`)*pi()/180))))*180/pi())*60*1.1515) as distance FROM (`modx_site_content` AS sc, `modx_site_tmplvars` AS lat_tv , `modx_site_tmplvars` AS lng_tv) LEFT JOIN `modx_site_tmplvar_contentvalues` AS lat_tvcv ON lat_tvcv.contentid = sc.id AND lat_tvcv.tmplvarid = lat_tv.id LEFT JOIN `modx_site_tmplvar_contentvalues` AS lng_tvcv ON lng_tvcv.contentid = sc.id AND lng_tvcv.tmplvarid = lng_tv.id WHERE sc.`id` IN (44,48) AND sc.`published`= 1 AND sc.`deleted`= 0 AND lat_tv.name = 'bild' AND lng_tv.name = 'head' ORDER BY distance ASC LIMIT 0,50
* Returns a lat / long of a given postcode
*
*/
function get_lat_long($postcode,$domain=null) {
if(!$domain) {
$domain = "co.uk";
}
$url = "http://maps.google.co.uk/maps/geo?q=" . urlencode($postcode) . "&output=json&key=ABQIAAAAdN8m5F_H4c8QnCWINywTCRQismpbGqJLdUil0k2vBhWw9rjFrhQVLNLfqmHZNGHxY1tlASp_Wx06bQ";
$json = $this->curl->get_page(array("url"=>$url));
$store_data = json_decode(str_replace(""","\"",htmlentities($json))); //Take care of accents
$lng = $store_data->Placemark[0]->Point->coordinates[0];
$lat = $store_data->Placemark[0]->Point->coordinates[1];
//Return
if($lng && $lat) {
return array('lat'=>$lat,
'lng'=>$lng
);
} else {
return false;
}
}
/**
* Get a list of our stores, sorted by distance to this postcode
*
*/
function get_stores_list($postcode) {
//If it's a UK postcode then format correctly
$postcode = $this->checkPostcode($postcode);
$latlng = $this->get_lat_long($postcode);
if(!$latlng) { //Unrecognised postcode
return false;
}
$latitude = $latlng['lat'];
$longitude = $latlng['lng'];
// print_r($latlng);
$query = "SELECT distinct
sc.pagetitle ,
sc.content ,
(((acos(sin((51.4926591*pi()/180)) * sin((lat_tvcv.value*pi()/180)) +cos((51.4926591*pi()/180)) * cos((lat_tvcv.value*pi()/180)) * cos(((-0.0542387- lng_tvcv.value)*pi()/180))))*180/pi())*60*1.1515)
as distance
FROM (
`modx_site_content` AS sc,
`modx_site_tmplvars` AS lat_tv ,
`modx_site_tmplvars` AS lng_tv)
LEFT JOIN `modx_site_tmplvar_contentvalues` AS lat_tvcv
ON lat_tvcv.contentid = sc.id AND lat_tvcv.tmplvarid = lat_tv.id
LEFT JOIN `modx_site_tmplvar_contentvalues` AS lng_tvcv
ON lng_tvcv.contentid = sc.id AND lng_tvcv.tmplvarid = lng_tv.id
WHERE sc.`parent` IN (".$parent.") AND sc.`published`= '1' AND sc.`deleted`= '0'
AND lat_tv.name = 'latitude'
AND lng_tv.name = 'longitude'
ORDER BY distance ASC
LIMIT 0,50
";
$stores = $this->db->executeQuery($query);
$stores = $stores['result'];
return $stores;
}
$parent='yourfolderwhereyouhaveyourstores';
$rs=$modx->db->query($query); $stores=$modx->db->makeArray($rs);