mysql SQL code for selecting nearby entries longitute latitude

in mysql •  8 years ago 

$stmt = $pdodb->prepare("SELECT field1, field2, SQRT(

    POW(69.1 * (dblat - :dblat), 2) +

    POW(69.1 * (:dblon - dblon) * COS(dblat / 57.3), 2)) AS distance

FROM tablename HAVING distance < :distance");


$stmt->bindParam(':dblat', $lat);

$stmt->bindParam(':dblon', $lon);

$stmt->bindParam(':distance', $distance); // in miles

$stmt->execute();

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!