forked from Waicung/WayFindingServerSide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointsUpdater.php
More file actions
46 lines (41 loc) · 1.29 KB
/
pointsUpdater.php
File metadata and controls
46 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* Created by PhpStorm.
* User: waicung
* Date: 24/04/2016
* Time: 22:34
*/
//testing code for insertion when no point found
//return the point_id in both way
/*echo "abcdefg";
require_once __DIR__ . '/db_config.php';
$conn=mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
$updator = new pointsUpdater();
$lat = -37.799901;
$lng = 144.943267;
$result = $updator->updatePoint($conn,$lat,$lng);
echo "abcdefg";
echo $result;*/
class pointsUpdater
{
function updatePoint($conn, $lat, $lng, $name){
$search_query = "SELECT * FROM way_points WHERE latitude = $lat AND longitude = $lng";
$search = mysqli_query($conn,$search_query);
if(!empty($search)&&mysqli_num_rows($search)>0){
$point = mysqli_fetch_array($search);
//if exist, return point_id
$point_id = $point['point_id'];
return $point_id;
}
else {
if($name==""){
$insert_query = "INSERT INTO way_points (latitude, longitude) VALUES ($lat,$lng)";
}
else{
$insert_query = "INSERT INTO way_points (latitude, longitude, name) VALUES ($lat,$lng,'$name')";
}
mysqli_query($conn, $insert_query);
return $this->updatePoint($conn, $lat, $lng, $name);
}
}
}