Skip to content

Instantly share code, notes, and snippets.

@anoochit
Last active April 17, 2017 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anoochit/48a98ffe3e09f43f79e7c753451fe911 to your computer and use it in GitHub Desktop.
Save anoochit/48a98ffe3e09f43f79e7c753451fe911 to your computer and use it in GitHub Desktop.
nearby query from drupal fields, filter gender first and query nearby location
SELECT *,( 3959 * acos( cos( radians(13.785872) ) * cos( radians( field_location_lat ) ) * cos( radians( field_location_lng ) - radians(100.570635) ) + sin( radians(13.785872) ) * sin( radians( field_location_lat ) ) ) ) AS distance
FROM (
SELECT users_field_data.uid,users_field_data.name, user__field_contact_line.field_contact_line_value,user__field_gender.field_gender_target_id,user__field_location.field_location_lat,user__field_location.field_location_lng
FROM users_field_data,user__field_contact_line,user__field_location,user__field_gender
WHERE users_field_data.status=1
AND users_field_data.uid=user__field_contact_line.entity_id
AND users_field_data.uid=user__field_location.entity_id
AND users_field_data.uid=user__field_gender.entity_id
AND user__field_gender.field_gender_target_id=2
) AS a
HAVING distance < 5
ORDER BY distance
LIMIT 0,5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment