title: Codeigniter selecting data with multiple id's
body: <p>Here is an example of my code and an explanation what I am trying to do.</p>
  
  <p>At the beginning of the code I am selecting three variables in my database. I then compare them to a function that determines the distance, if the distance is within the given distance then I have the id of that record. This will result in multiple id's. Could be five or none, depends on the variables given.</p>
  
  <p>What I need to know is once I have determined that id I need to use I need to put into either a variable or something else that is manageable. Basically I need to take the list and query the database again to get the list of details from the database. The list will return objects that will later be past to <code>json_encode</code> for processing. </p>
  
  <p>What I need to know is what is the best way to put each id into a variable and pass it to a database query and get the results I need.</p>
  
  <p>I've tried using <code>$dbStations-&gt;where('_id', '34,33,45')</code> but it only returns the first value. I need something like <code>WHERE _id = 34 AND 33 AND 45</code> if possible.</p>
  
  <p>I am using Codeigniter for my framework and I have went over the documentation and I have not found a solution.</p>
  
  <p>EDIT: 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>