I'm trying to fetch a load of database entries which include geo data that has to be fetched from another table. When i try to run a custom distance function on them it causes an error, I have tried to include it as a sub query but that does not seem to work either (The function does work).
$bsns = $this->db->select('businesses.name, businesses.about')
->select('postcodes.postcode, postcodes.lat AS lat, postcodes.long AS long')
->select('industries.name')
->select('get_distance_in_miles_between_geo_locations('.$geo['lat'].', '.$geo['long'].', lat, long) AS distance', null, false)
->from('businesses')
->join('postcodes', 'postcodes.postcode = businesses.postcode', 'left')
->join('industries', 'industries.IN_ID = businesses.industry', 'left')
->order_by('distance', 'ASC')
->get();
This is the code i'm using at the moment, The error:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'long, `industries`.`name`, get_distance_in_miles_between_geo_locations(50.344178' at line 1
New error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'businesses`) LEFT JOIN `postcodes` ON `postcodes`.`postcode` = `businesses`.`pos' at line 1
SELECT `businesses`.`name`, `businesses`.`about`, `postcodes`.`postcode`, `postcodes`.`lat`, `postcodes`.`long`, `industries`.`name`, get_distance(50.344178, `-4`.`757147`, `lat`, `long`)` AS distance FROM (`businesses`) LEFT JOIN `postcodes` ON `postcodes`.`postcode` = `businesses`.`postcode` LEFT JOIN `industries` ON `industries`.`IN_ID` = `businesses`.`industry` ORDER BY `distance` ASC