catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

Use ACOS/SIN/COS functions with Medoo #483

Closed jdanielcmedina closed 3 years ago

jdanielcmedina commented 8 years ago

Hi, I need use this with Medoo.

        SELECT `id`, (((ACOS(SIN((" . $latitude . " * PI()/180)) * SIN((`latitude` * PI()/180)) + COS((" . $latitude . " * PI()/180)) * COS((`latitude` * PI()/180)) * COS(((" . $longitude . " - `longitude`) * PI()/180)))) * 180/PI()) * 60 * 1.1515 * 1.609344) AS dist
        FROM users
        ORDER BY dist

But I want use like this... $database->get('users', '*', [?????]);

Thanks...

jdanielcmedina commented 8 years ago

I add this function inside Medoo class and works good. I need put inside class because I need use WHERE clause function....

public function distance($table, $latitude = 0, $longitude = 0, $where = null){

$query = $this->query('SELECT id, (((ACOS(SIN((' . $latitude . ' * PI()/180)) * SIN((latitude * PI()/180)) + COS((' . $latitude . ' * PI()/180)) * COS((latitude * PI()/180)) * COS(((' . $longitude . ' - longitude) * PI()/180)))) * 180/PI()) * 60 * 1.1515 * 1.609344) AS distance FROM users ' . $this->where_clause($where));

    return $query->fetchAll(PDO::FETCH_ASSOC);
}