Issues retrieving doubles from database

edited July 2015 in Bug Reports
I've having a problem getting the data for doubles (latitude and longitude) out of the database. The database is showing huge precision, but the data from the query is truncating everything after the decimal.

I have a model just for getting "targets" related to a "project".

Here's one of the functions:
public function get_project_targets($project_id) { $this->db->select('navtech_targets.id as id, navtech_projects.name as project, navtech_targets.layer as layer, navtech_targets.name as name, navtech_targets.latitude as latitude, navtech_targets.longitude as longitude', FALSE); $this->db->join($this->_tables['navtech_projects'], $this->_tables['navtech_projects'].'.id = '.$this->_tables['navtech_targets'].'.navtech_project_id', 'left'); $where = array('navtech_project_id'=>$project_id); $data = $this->find_all($where); return $data; }

The record code (derived from Base_module_record) has this:
public function get_project_data() { //echo $this->latitude; $values = array( 'id' => $this->id, 'project' => $this->project, 'layer' => $this->layer, 'name' => $this->name, 'latitude' => $this->latitude, 'longitude' => $this->longitude); return $values; }

So, where the database might have the following:
latitude => 51.002891540527344 longitude => -114.0547866821289
I get:
latitude => 51 longitude => -114
Type in PHP says it's a float(51) and float(-114).

Any ideas or suggestions?

Comments

  • edited 8:49AM
    When I had problems retrieving lats & longs from my data a few years ago (before I started using Fuel), I converted them to strings - I've not looked back since...
  • edited July 2015
    In one case, where the lat/longs are working, it appears as if they are being treated as strings (arrays converted to JSON):
    [{"crew":"Crew 4659","crew_type":"Survey","project":"Calgary_2015_05_06","latitude":"51.002985485829","longitude":"-114.055138751864","date_added":"2015-07-20 21:10:42.000","id":"8599"}, {"crew":"Crew 11","crew_type":"Survey","project":"Calgary_2015_05_06","latitude":"51.002873587422","longitude":"-114.056238792837","date_added":"2015-07-20 21:10:10.000","id":"8597"}, {"crew":"Crew 1046","crew_type":"Slashers","project":"Calgary_2015_05_06","latitude":"51.00244138","longitude":"-114.0547902","date_added":"2015-07-20 20:08:43.000","id":"8463"}, {"crew":"Crew 10","crew_type":"Supervisor","project":"Calgary_2015_05_06","latitude":"51.002750289626","longitude":"-114.054845888168","date_added":"2015-07-20 21:10:54.000","id":"8596"}]

    But in two other tables they are being treated as (possibly?) ints.
    [{"id":1,"project":"Calgary_2015_05_06","layer":"post_plot_source","name":"1001","latitude":51,"longitude":-114}, {"id":2,"project":"Calgary_2015_05_06","layer":"post_plot_source","name":"1002","latitude":51,"longitude":-114}, {"id":3,"project":"Calgary_2015_05_06","layer":"post_plot_source","name":"1003","latitude":51,"longitude":-114}, {"id":4,"project":"Calgary_2015_05_06","layer":"post_plot_source","name":"1004","latitude":51,"longitude":-114}, {"id":5,"project":"Calgary_2015_05_06","layer":"post_plot_source","name":"2001","latitude":51,"longitude":-114}, {"id":6,"project":"Calgary_2015_05_06","layer":"post_plot_source","name":"2002","latitude":51,"longitude":-114}, {"id":7,"project":"Calgary_2015_05_06","layer":"post_plot_source","name":"2003","latitude":51,"longitude":-114}, {"id":8,"project":"Calgary_2015_05_06","layer":"post_plot_source","name":"2004","latitude":51,"longitude":-114}, {"id":9,"project":"Calgary_2015_05_06","layer":"post_plot_source","name":"2005","latitude":51,"longitude":-114}]

    [{"id":1,"project":"Calgary_2015_05_06","layer":"post_plot_source","name":"1001","crew":"1046","latitude":51,"longitude":-114,"date_added":"2015-02-20 16:30:55"}]
  • edited 8:49AM
    Converting the mySql field types to VARCHAR worked.
Sign In or Register to comment.