Sorry to be a pain, but I suck at SQL so can’t even get my head around the theory of what I’m trying to do this time..
This is similar to my venue search, but this time it’s an ‘event’ search. Each event ‘has one’ venue, and I want to filter events by venues that within 5 miles of the location entered.
The code below works, except it overrides the values in my $event instance. For example, both events and venues have a field ‘url_segment’, the code below overrides the event url segment with the venue one, and I can’t access the venue by doing $event->venue->name, I have to do $event->name.
What am I doing wrong here?
$event = new Event();
$result['status'] = 'success';
if ($location AND $location != 'any' AND strlen($location) >= 3)
$l = new Location();
// Either get existing lat/lon if exists, or encode new one
$location = $l->exists() ? $l->where('name', $location)->get(1) : $this->add_gmap_json($location);
$venue = new Venue();
$event->select_related($venue, '*, (((acos(sin(('.$location->lat.' *pi()/180))*sin((`lat`*pi()/180))+cos(('.$location->lat.'*pi()/180))*cos((`lat`*pi()/180))*cos((('.$location->lon.'-`lon`)*pi()/180))))*180/pi())*60*1.1515) as distance');
$event->having('distance < 5');
$result['loc'] = $location;
$result['status'] = 'error';
/* more filtering */
$clone = $event->get_clone();
$result['num_rows'] = $clone->result_count();
if ($limit OR $offset)
$result['results'] = $event->get();
Thanks again for your help!