2

Yea, Ill admit the subject to this post is not perfect. However I have no idea how to word it currently.

What I am trying to do is avoid the $this->db->query($sql); type of statement. I would prefer to use this in an active record method, but I am unsure how to do that at the moment.

my Query is set to look something to the concept of

select loc.distance,
loc.user,
loc.lat,
loc.lon,
baseinfo.firstname,
baseinfo.lastname,
(((acos(sin((".$this->db->escape($lat)."*pi()/180)) * sin((`latitude`*pi()/180))+cos((".$this->db->escape($lat)."*pi()/180)) * cos((`latitude`*pi()/180)) * cos(((".$this->db->escape($lon)." - `longitude`)*pi()/180))))*180/pi())*60*1.1515) AS `distance`
FROM memb_geo_locations loc

Then it gets a little more extensive as I build out the rest with potential LEFT JOINS, JOINS, etc..

But this guy..

(((acos(sin((".$this->db->escape($lat)."*pi()/180)) * sin((`latitude`*pi()/180))+cos((".$this->db->escape($lat)."*pi()/180)) * cos((`latitude`*pi()/180)) * cos(((".$this->db->escape($lon)." - `longitude`)*pi()/180))))*180/pi())*60*1.1515) AS `distance`

I am not sure how to tie that into the active record method, and I am seeking some help. Any ideas?

2
  • I have recently given an answer about that you can check. stackoverflow.com/questions/15400938/… Commented Mar 17, 2013 at 12:59
  • I'm kinda understanding that, notion, but at the same time not so much, as its a bit different than what I think I am looking for overall. That and if I can (and I have to this date), stay out of the system folder and editing any files within, as I don't want to cause potential conflict down the road when it comes time to upgrade CI (if they ever push a notable release worthy of upgrading) Commented Mar 17, 2013 at 13:05

1 Answer 1

1
        $this->db->select('loc.distance,
        loc.user,
        loc.lat,
        loc.lon,
        baseinfo.firstname,
        baseinfo.lastname,
        (((acos(sin(('.$this->db->escape($lat).'*pi()/180)) * sin((`latitude`*pi()/180))+cos(('.$this->db->escape($lat).'*pi()/180)) * cos((`latitude`*pi()/180)) * cos((('.$this->db->escape($lon).' - `longitude`)*pi()/180))))*180/pi())*60*1.1515) AS `distance`
        ');
        $this->db->from('loc');
       //then all stuffs you need more... like
       $this->db->join();
       //etc..
      $query = $this->db->get('memb_geo_locations');
      return $query->result();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.