php - Updating Database And Query Based On Location -
for last few days i've been trying fix code in android can onlocationchanged () send new latitude , longitude database , when it's updated want query based on location. i'm having trouble doing android , wondering if there way "combine" 2 php codes use updating , querying database. both codes work separately, can combined? need database updated new data , query or vice versa.
update.php
$latitude1 = $_post["latitude"]; $longitude1 = $_post["longitude"]; $username = $_post["username"]; $updatequery = mysqli_prepare($con , "update users set latitude = ?, longitude = ? username = ?"); mysqli_stmt_bind_param($updatequery ,"dds",$latitude1,$longitude1,$username); mysqli_stmt_execute($updatequery); mysqli_stmt_close($updatequery); mysqli_close($con);
querybylocation.php
$origlat = $_post["latitude"]; $origlon = $_post["longitude"]; $dist = 30; $id = $_post["id"]; if(mysqli_connect_errno($con)) { die("connection failed : " . mysqli_connect_error()); } $sql = "select id, name, age, city, gender, latitude, longitude, 3956 * 2 * 1.609344 * 1000 * asin(sqrt( power(sin(($origlat - abs(latitude))*pi()/180/2),2) +cos($origlat*pi()/180 )*cos(abs(latitude)*pi()/180) *power(sin(($origlon-longitude)*pi()/180/2),2))) distance users id != '$id' , longitude between ($origlon-$dist/abs(cos(radians($origlat))*69)) , ($origlon+$dist/abs(cos(radians($origlat))*69)) , latitude between ($origlat-($dist/69)) , ($origlat+($dist/69)) having distance < $dist order distance limit 30;"; $result = mysqli_query($con, $sql); $rows = array(); while($row = mysqli_fetch_array($result, mysqli_assoc)) { $rows[] = $row; } mysqli_close($con); echo json_encode($rows);
$origlat = $_post["latitude"]; $origlon = $_post["longitude"]; $dist = 30; $id = $_post["id"]; $username = $_post["username"]; if(mysqli_connect_errno($con)) { die("connection failed : " . mysqli_connect_error()); } $updatequery = mysqli_prepare($con , "update users set latitude = ?, longitude = ? username = ?"); mysqli_stmt_bind_param($updatequery ,"dds",$origlat,$origlon,$username); mysqli_stmt_execute($updatequery); mysqli_stmt_close($updatequery); $sql = "select id, name, age, city, gender, latitude, longitude, 3956 * 2 * 1.609344 * 1000 * asin(sqrt( power(sin(($origlat - abs(latitude))*pi()/180/2),2) +cos($origlat*pi()/180 )*cos(abs(latitude)*pi()/180) *power(sin(($origlon-longitude)*pi()/180/2),2))) distance users id != '$id' , longitude between ($origlon-$dist/abs(cos(radians($origlat))*69)) , ($origlon+$dist/abs(cos(radians($origlat))*69)) , latitude between ($origlat-($dist/69)) , ($origlat+($dist/69)) having distance < $dist order distance limit 30;"; $result = mysqli_query($con, $sql); $rows = array(); while($row = mysqli_fetch_array($result, mysqli_assoc)) { $rows[] = $row; } mysqli_close($con); echo json_encode($rows);
Comments
Post a Comment