php - Convert Mysql query to cakephp conditions -
i want convert query cakephp
select l.* , ( ( ( acos( sin( ( $lat * pi( ) /180 ) ) * sin( ( l.lat * pi( ) /180 ) ) + cos( ( $lat * pi( ) /180 ) ) * cos( ( l.lat * pi( ) /180 ) ) * cos( ( ( $lng - l.long ) * pi( ) /180 ) ) ) ) *180 / pi( ) ) *60 * 1.1515 * 1.609344 ) `distance` hosts l having `distance` <= 50 order `distance` asc
help me please ..... more helpfull if can add in contiions array like
$this->paginate = array('conditions' => $conditions , 'order' => array('host.distance' => 'asc') );
you try redefine virtual field before calling model::find:
// controller code $this->note->virtualfields = array( 'distance' => "( 3959 * acos( cos( radians($lat) ) * cos( radians( note.latitude ) ) * cos( radians( note.longitude ) - radians($lng) ) + sin( radians($lat) ) * sin( radians( note.latitude ) ) ) )" ); $data = $this->note->find('all', array('fields' => array('distance'), 'conditions' => array('distance <' => 1)));
if works, you'll want create model method that
and can pagination also.
Comments
Post a Comment