Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6657277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:44:52+00:00 2026-05-26T01:44:52+00:00

Here is an example of my code and an explanation what I am trying

  • 0

Here is an example of my code and an explanation what I am trying to do.

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.

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 json_encode for processing.

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.

I’ve tried using $dbStations->where('_id', '34,33,45') but it only returns the first value. I need something like WHERE _id = 34 AND 33 AND 45 if possible.

I am using Codeigniter for my framework and I have went over the documentation and I have not found a solution.

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.

Example of json: {"details":[{"country":"United States","_id":"3892","lat":"39.954559","lng":"-82.837608","admin_level_1":"Ohio","locale":"Columbus"}]}

This is what it needs to be, keep in mind that distance is not in the database, it is calculated on the fly.

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"}]}

Any ideas on how to get ths distance that is caculcated to be appended to the end of each result?

        $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()));
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:44:52+00:00Added an answer on May 26, 2026 at 1:44 am

    Try using where_in()

    $ids = array(33, 34, 45);
    $dbStations->where_in('id', $ids);
    // Produces: WHERE id IN (33, 34, 45)
    

    This will return records that have the ID of 33, 34, 45

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a simple, barebones example of how the code that I'm trying to do
Here's some example code: class Obj attr :c, true def == that p '=='
For example, my goal is to test the code given here: PHP script that
here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
I'm looking for something like break for loops. Here's some example code (using Symfony's
Here is an example of my code in a DAL. All calls to the
Is there a way to execute internal code via reflection? Here is an example
Here is my current code: RewriteCond %{HTTP_HOST} !^example\.com [NC] #RewriteCond %{REQUEST_URI}!^something RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
To use a contrived example in Java, here's the code: enum Commands{ Save(S); File(F);
I'm trying to make a function that can be applied to a value returned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.