I want to fetch rows from mysql database with filter by near by and the limit of distance
up vote
0
down vote
favorite
I want to fetch rows from MySql
database with filter by near by and the limit of distance. I have created a query that is working fine for fetching the data near by, but I want to add a condition for distance limitation, that means If I want rows which have location of 20 km distance.
This is the query that is working for near by.
$lat="";
$lon="";
$sql="SELECT *,
111.111 *
DEGREES(ACOS(COS(RADIANS(".$lat."))
* COS(RADIANS(Lat))
* COS(RADIANS(".$lon." - Lon))
+ SIN(RADIANS(".$lat."))
* SIN(RADIANS(Lat)))) AS d
FROM Table
ORDER BY d"
php mysql location
add a comment |
up vote
0
down vote
favorite
I want to fetch rows from MySql
database with filter by near by and the limit of distance. I have created a query that is working fine for fetching the data near by, but I want to add a condition for distance limitation, that means If I want rows which have location of 20 km distance.
This is the query that is working for near by.
$lat="";
$lon="";
$sql="SELECT *,
111.111 *
DEGREES(ACOS(COS(RADIANS(".$lat."))
* COS(RADIANS(Lat))
* COS(RADIANS(".$lon." - Lon))
+ SIN(RADIANS(".$lat."))
* SIN(RADIANS(Lat)))) AS d
FROM Table
ORDER BY d"
php mysql location
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to fetch rows from MySql
database with filter by near by and the limit of distance. I have created a query that is working fine for fetching the data near by, but I want to add a condition for distance limitation, that means If I want rows which have location of 20 km distance.
This is the query that is working for near by.
$lat="";
$lon="";
$sql="SELECT *,
111.111 *
DEGREES(ACOS(COS(RADIANS(".$lat."))
* COS(RADIANS(Lat))
* COS(RADIANS(".$lon." - Lon))
+ SIN(RADIANS(".$lat."))
* SIN(RADIANS(Lat)))) AS d
FROM Table
ORDER BY d"
php mysql location
I want to fetch rows from MySql
database with filter by near by and the limit of distance. I have created a query that is working fine for fetching the data near by, but I want to add a condition for distance limitation, that means If I want rows which have location of 20 km distance.
This is the query that is working for near by.
$lat="";
$lon="";
$sql="SELECT *,
111.111 *
DEGREES(ACOS(COS(RADIANS(".$lat."))
* COS(RADIANS(Lat))
* COS(RADIANS(".$lon." - Lon))
+ SIN(RADIANS(".$lat."))
* SIN(RADIANS(Lat)))) AS d
FROM Table
ORDER BY d"
php mysql location
php mysql location
asked yesterday
Romil Singh Tomar
137
137
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You can use HAVING Clause to achieve this
$sql="SELECT *,
111.111 *
DEGREES(ACOS(COS(RADIANS(".$lat."))
* COS(RADIANS(Lat))
* COS(RADIANS(".$lon." - Lon))
+ SIN(RADIANS(".$lat."))
* SIN(RADIANS(Lat)))) AS d
FROM Table HAVING d <= 20
ORDER BY d"
(orWHERE 111.111 * ... <=20
)
– Strawberry
yesterday
1
Thanks, It's working
– Romil Singh Tomar
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can use HAVING Clause to achieve this
$sql="SELECT *,
111.111 *
DEGREES(ACOS(COS(RADIANS(".$lat."))
* COS(RADIANS(Lat))
* COS(RADIANS(".$lon." - Lon))
+ SIN(RADIANS(".$lat."))
* SIN(RADIANS(Lat)))) AS d
FROM Table HAVING d <= 20
ORDER BY d"
(orWHERE 111.111 * ... <=20
)
– Strawberry
yesterday
1
Thanks, It's working
– Romil Singh Tomar
yesterday
add a comment |
up vote
0
down vote
accepted
You can use HAVING Clause to achieve this
$sql="SELECT *,
111.111 *
DEGREES(ACOS(COS(RADIANS(".$lat."))
* COS(RADIANS(Lat))
* COS(RADIANS(".$lon." - Lon))
+ SIN(RADIANS(".$lat."))
* SIN(RADIANS(Lat)))) AS d
FROM Table HAVING d <= 20
ORDER BY d"
(orWHERE 111.111 * ... <=20
)
– Strawberry
yesterday
1
Thanks, It's working
– Romil Singh Tomar
yesterday
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can use HAVING Clause to achieve this
$sql="SELECT *,
111.111 *
DEGREES(ACOS(COS(RADIANS(".$lat."))
* COS(RADIANS(Lat))
* COS(RADIANS(".$lon." - Lon))
+ SIN(RADIANS(".$lat."))
* SIN(RADIANS(Lat)))) AS d
FROM Table HAVING d <= 20
ORDER BY d"
You can use HAVING Clause to achieve this
$sql="SELECT *,
111.111 *
DEGREES(ACOS(COS(RADIANS(".$lat."))
* COS(RADIANS(Lat))
* COS(RADIANS(".$lon." - Lon))
+ SIN(RADIANS(".$lat."))
* SIN(RADIANS(Lat)))) AS d
FROM Table HAVING d <= 20
ORDER BY d"
answered yesterday
Amit Sahu
22116
22116
(orWHERE 111.111 * ... <=20
)
– Strawberry
yesterday
1
Thanks, It's working
– Romil Singh Tomar
yesterday
add a comment |
(orWHERE 111.111 * ... <=20
)
– Strawberry
yesterday
1
Thanks, It's working
– Romil Singh Tomar
yesterday
(or
WHERE 111.111 * ... <=20
)– Strawberry
yesterday
(or
WHERE 111.111 * ... <=20
)– Strawberry
yesterday
1
1
Thanks, It's working
– Romil Singh Tomar
yesterday
Thanks, It's working
– Romil Singh Tomar
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372372%2fi-want-to-fetch-rows-from-mysql-database-with-filter-by-near-by-and-the-limit-of%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown