Hello, Thanks for the tip, I ended up with something like :
function findAllByD($x, $y, $distance = null, $day, $recursive) { ..... $x2 = "`TblClassLocation`.`classLocationLong`"; $y2 = "`TblClassLocation`.`classLocationLat`"; return $this->find('all',array( 'limit'=>'1000', 'order'=>'distance ASC', 'fields'=>" *, (3958 * 3.1415926 * SQRT(({$y2} - {$y}) * ({$y2} - {$y}) + COS({$y2} / 57.29578) * COS({$y} / 57.29578) * ({$x2} - {$x}) * ({$x2} - {$x})) / 180) AS distance", 'conditions'=>" 1=1 HAVING distance <= {$distance} ......... Andras On Sep 20, 7:13 pm, Joe <[EMAIL PROTECTED]> wrote: > I did similar MySQL geocoding situation where I had to use HAVING and > ended up with something like this, you'll probably have to tweak it > for your own system. > > http://blog.joebeeson.com/wp-content/uploads/2008/08/query.jpg > > Sorry it's an image, didn't feel like typing it all back up. The > original post is herehttp://blog.joebeeson.com/?p=125if it helps at > all. > > On Sep 19, 10:51 am, AndrasKende<[EMAIL PROTECTED]> wrote: > > > Hello, > > > Im using the geocode behaviour > > fromhttp://bakery.cakephp.org/articles/view/geocoding-in-cakephp > > > findAllByDistance(........ > > ....... > > $model->find('all',array('conditions'=>"(3958 * 3.1415926 * > > SQRT(({$y2} - {$y}) * ({$y2} - {$y}) + COS({$y2} / 57.29578) * > > COS({$y} / 57.29578) * ({$x2} - {$x}) * ({$x2} - {$x})) / 180) <= > > {$distance}")); > > ..... > > > Works fine, but would like to add virtual 'distance' into the query so > > results can be sorted by shortest distance > > > I think this is could be done with MySQL HAVING statement ? > > > maybe similar too: > > > SELECT id, ( 3959 * acos( cos( radians(blahblah) ) * > > cos( radians( lat ) ) * cos( radians( lng ) - radians(blahblah) ) + > > sin( radians(blah) ) *sin( radians( lat ) ) ) ) AS distance FROM > > markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20; > > > Thanks for any help!!! > > > Andras > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---