<?php
ini_set("display_errors", 1);
if (!defined('BASEPATH'))
	exit('No direct script access allowed');


class Md_farmacia extends CI_Model {

  public function getSucur($search) {
		$otherdb = $this->load->database('sucursales', TRUE);
		$otherdb->select('*');
		$otherdb->from('sucursales');
		$otherdb->like('sucursal', $search);
		$otherdb->limit(5);
		return $otherdb->get()->result_array();
	}

	public function getNearby($lat, $long) {
		$otherdb = $this->load->database('sucursales', TRUE);
		$otherdb->select('*, (ACOS(COS(RADIANS('.$lat.')) * COS(RADIANS(latitud)) * COS(RADIANS(longitud) - RADIANS('.$long.')) + SIN(RADIANS('.$lat.')) * SIN(RADIANS(latitud)))) / 0.000156961230576 AS distance FROM sucursales HAVING distance <= 3 ORDER BY distance ASC');
		$otherdb->limit(5);
		$return = $otherdb->get()->result_array();
		return $return;
	}

}
