I am trying to run a query based on what is stated in the title, select records close to each other, with between two dates of birth, without success
so far I have tried this looking from left to right, what I want is to return only the users who are between the dates that the current user will have sent in post, and between the distance
if (!function_exists('Dot_Distance')) {
function Dot_Distance($lat_u, $long_u, $or, $sex, $age, $age_tow, $age_olders, $uid, $distance){
global $db;
$latitude = $lat_u;
$longitude = $long_u;
$distance = $distance;
$sagea = 'AND ('.$age_olders.' BETWEEN (YEAR(CURDATE())- ' . $age . ') AND (YEAR(CURDATE())-' . $age_tow . '))';
$query = $db->prepare("SELECT *, (((acos(sin(( $latitude * pi() / 180)) *sin(( `lat_` * pi() / 180)) +
cos(( $latitude * pi() /180 ))*cos(( `lat_` * pi() / 180)) * cos((( $longitude - `long_`) *
pi()/180)))) * 180/pi()) * 60 * 1.1515 * 1.609344) as distance
FROM `users`
WHERE
lat_ IS NOT NULL AND
long_ IS NOT NULL
AND
orientation = '$or'
AND sex = '$sex'
$sagea // return 2008-07-05 / 2011-07-05
AND id <> '$uid'
HAVING distance < '$distance'
ORDER BY distance * 1 ASC");
$query->execute();
$query = $query->fetchAll(PDO::FETCH_OBJ);
// var_dump($sagea);
return $query;
}
}
// a not
Thanks in advance
New contributor
Dk Tuto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.