I have a php Mysql query which returns a recordset containing id, Name, Type, Latitude, Longitude, Distance
I have searched for a solution to encode the results as json but all the examples show the array being treated as a whole.
$json = array();
if(mysql_num_rows($result)){
while($row=mysql_fetch_row($result)){
$json['markers'][]=$row;
}
}
echo json_encode($json);
Which works fine and produces the following json:
{"markers":[
["2110","AP","Nans Sous Sainte Anne","46.976810","5.998910","1.60316506124051","0","0","0"],
["3484","AC","Salins Les Bains","46.946568","5.878649","6.8092722205639","0","0","0"], ["2136","AC","Levier","46.959862","6.132840","6.8490368219444","0","1","0"],
["3472","APN","Salins Les Bains","46.936852","5.876290","7.28462233818928","0","0","0"],["3466","ASN","Salins Les Bains","46.932541","5.878990","7.36798013180542","0","2","0"],["2158","FP","Domaine d'Esprits","47.035751","5.824800","8.6152043630634","0","0","0"]]}
But what I want to do is loop through each row and use the Latitude and Longitude in a function to get the bearing using the following function; $center_lat and $center_lng are passed in the url as the search center.
$bearing=getCompassDirection(getBearing($center_lat, $center_lng, $row['Latitude'], $row['Longitude']));
The function 'getCompassDirection' is valid and works, but how do I loop through my_sql result and apply the function to each row?