简体   繁体   中英

How to scroll through a count query in MySQL/PHP

I have this query:

select count(*) , ( 3959 * acos( cos( radians( 34.469994 ) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians( -118.196739 ) ) + sin( radians( 34.469994 ) ) * sin( radians( lat ) ) ) ) AS distance from users HAVING distance < 150

Which is supposed to get users within 150 miles of a certain latitude and longitude.
How can I get the number of the count(*) part?

Also, any idea how to toggle such a query between miles and kilometers?

Thanks!

select count(*) as count, ( 3959 * acos( cos( radians( 34.469994 ) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians( -118.196739 ) ) + sin( radians( 34.469994 ) ) * sin( radians( lat ) ) ) ) AS distance from users HAVING distance < 150

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM