My returned array is coming back in this strange format that is not valid. At least not in my AJAX experience.
function get_within($latitude, $longitude) {
global $pdo;
// $lat = $latitude;
// $long = $longitude;
// $long = '-70.98245279999999';
// $lat = '41.98156549999999';
$stmt = $pdo->prepare("SELECT menu_id, latitude, longitude ( acos(
cos( radians(".$latitude." ) ) *
cos( radians( latitude) ) *
cos( radians(".$longitude.") - radians(longitude)) +
sin( radians(".$latitude.") ) * sin( radians(latitude) ) ))*.621371192
as dis from pages where 1 ORDER BY `dis` ASC LIMIT 10");
$stmt->execute( array() );
return $stmt->fetchAll( PDO::FETCH_OBJ );
I made an AJAX request using the above function. I need it to return an object but it is only returning an array like this:
[{"id":"26","subject_id":"5","menu_name":"Bobby Byrne's Food & Pub\u200e","position":"1","visible":"1","content":"Bobby Byrne's Restaurant & Pub\u200e\r\n65 Massachusetts 6A, Sandwich, MA\r\n(508) 888-6088","longitude":"-70.508598","latitude":" 41.765754","dis":"0.00245126419033985"}]
What is wrong and how can I get back my query in objects correctly for use?
Your response is a JSON encoded object. You need to decode the JSON to an object.
Please see:
http://php.net/manual/en/ref.json.php