-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgetMapMarkers.php
38 lines (36 loc) · 1.01 KB
/
getMapMarkers.php
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
<?php
// Include config file
require_once 'config.php';
// Perform query
$sql = "SELECT lat, lng FROM places";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
// set array
$array = array();
while($row = mysqli_fetch_array($result)){
$array[] = $row;
}
class markerLocation
{
public $lat;
public $lng;
}
$parsedResult = array();
$arrLength = count($array);
for ($i=0; $i < $arrLength; $i++) {
$loc = new markerLocation();
$loc->lat = $array[$i][0];
$loc->lng = $array[$i][1];
array_push($parsedResult,$loc);
}
echo json_encode($parsedResult);
mysqli_free_result($result);
} else{
echo "<div class='alert alert-warning' role='alert'>No places were found in the database!</div>";
}
} else{
echo "ERROR: Unable to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>