I am new to Drupal 7/Views 3 hooks. I am trying to approximate this query:
SELECT *, 3956 * 2 * ASIN(SQRT(POWER(SIN(($postcode_lat - abs(lat))*pi()/180/2),2) + COS($postcode_lat * pi()/180) * COS(abs(lat) * pi()/180) * POWER(SIN(($postcode_lng - lng) * pi()/180/2),2))) AS distance
WHERE distance < 500
ORDER BY distance ASC
This gives a list of locations sorted by distance. However, in trying to implement with hooks, I am struggling. Here is the code that I tried:
$query->addField('', '3956 * 2 * ASIN(SQRT(POWER(SIN((32.7828 - abs(29.7631))*pi()/180/2),2) + COS(32.7828 * pi()/180) * COS(abs(29.7631) * pi()/180) * POWER(SIN((96.8039 - 95.2665) * pi()/180/2),2)))', 'distance');
Drupal doesn't like the empty parameter for table. But how can I add a field with no table?
I appreciate any suggestions offered.