我爲我的框架使用Codeigniter,並且我已經去了文檔,我還沒有找到解決方案。追加變量到每個結果
既然我已經從數據庫中選擇了數據,我需要在每個檢索到的記錄末尾顯示距離。
Example of json: {"details":[{"country":"United States","_id":"3892","lat":"39.954559","lng":"-82.837608","admin_level_1":"Ohio","locale":"Columbus"}]}
這是它需要的,請記住,距離不在數據庫中,它是在飛行中計算的。
Example of json: {"details":[{"country":"United States","_id":"3892","lat":"39.954559","lng":"-82.837608","admin_level_1":"Ohio","locale":"Columbus", "distance": "1.2 Mi"}]}
任何關於如何獲得距離的距離被追加到每個結果的末尾?
$dbStations->select('lat');
$dbStations->select('lng');
$dbStations->select('_id');
$stations = $dbStations->get('stDetails');
foreach ($stations->result() as $station) {
$lat2 = $station->lat;
$lng2 = $station->lng;
$stId = $station->_id;
$distance = $this->distance->gpsdistance($lat1, $lng1, $lat2, $lng2, "M");
if ($distance <= $rad) {
//at this point the code has determined that this id is within
//the preferred distance.
$stationArr[] = $stId;
}
}
$dbStations->select('country, _id, lat, lng, admin_level_1, locale');
$dbStations->where_in('_id', $stationArr);
$stations = $dbStations->get('stationDetails');
echo json_encode(array('stations' => $stations->result()));
}
'dbStations-> get('stDetails')''''dbStations-> get('stationDetails')'應該查詢同一個表嗎? – birderic