Note that there are some explanatory texts on larger screens.

plurals
  1. POAppend variable to end of each result
    primarykey
    data
    text
    <p>I am using Codeigniter for my framework and I have went over the documentation and I have not found a solution.</p> <p>Now that I have the the data selected from the database I need to get the distance to be displayed at the end of each record retrieved.</p> <pre><code>Example of json: {"details":[{"country":"United States","_id":"3892","lat":"39.954559","lng":"-82.837608","admin_level_1":"Ohio","locale":"Columbus"}]} </code></pre> <p>This is what it needs to be, keep in mind that distance is not in the database, it is calculated on the fly.</p> <pre><code>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"}]} </code></pre> <p>Any ideas on how to get ths distance that is caculcated to be appended to the end of each result?</p> <pre><code> $dbStations-&gt;select('lat'); $dbStations-&gt;select('lng'); $dbStations-&gt;select('_id'); $stations = $dbStations-&gt;get('stDetails'); foreach ($stations-&gt;result() as $station) { $lat2 = $station-&gt;lat; $lng2 = $station-&gt;lng; $stId = $station-&gt;_id; $distance = $this-&gt;distance-&gt;gpsdistance($lat1, $lng1, $lat2, $lng2, "M"); if ($distance &lt;= $rad) { //at this point the code has determined that this id is within //the preferred distance. $stationArr[] = $stId; } } $dbStations-&gt;select('country, _id, lat, lng, admin_level_1, locale'); $dbStations-&gt;where_in('_id', $stationArr); $stations = $dbStations-&gt;get('stationDetails'); echo json_encode(array('stations' =&gt; $stations-&gt;result())); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload