-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnothin.php
64 lines (50 loc) · 1.75 KB
/
nothin.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
define("servername", "localhost");
define("dbusername", "root");
define("dbpassword", "");
define("dbname", "mydb");
// if ($_SERVER["REQUEST_METHOD"] == "POST"){
// if(empty($_POST['username'])){
// echo "Session error";
// }
// else{
// $username=$_POST['username'];
function sql_to_coordinates($blob)
{
$blob = str_replace("))", "", str_replace("POLYGON((", "", $blob));
$coords = explode(",", $blob);
$coordinates = array();
foreach($coords as $coord)
{
$coord_split = explode(" ", $coord);
$coordinates[]=array("lat"=>$coord_split[0], "lng"=>$coord_split[1]);
}
return $coordinates;
}
$conn = new mysqli(servername, dbusername, dbpassword, dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$query ="SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(points))) as points FROM polygon WHERE username='mb' AND NOW() BETWEEN startDateTime AND endDateTime AND status='Active'";
$result = $conn->query($query);
$conn->close();// Closing Connection
if($result->num_rows > 0) {
// start xml file, create parent node
// $dom= new DOMDocument("1.0");
// $node = $dom->createElement("markers");
// $parnode = $dom->appendChild($node);
// header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = $result->fetch_assoc()) {
$var = sql_to_coordinates($row['points']);
}
echo $var;
// foreach ($var as $key => $value) {
// // $node = $dom->createElement("marker");
// // $newnode = $parnode->appendChild($node);
// // $newnode->setAttribute("lat",$value['lat']);
// // $newnode->setAttribute("lng",$value['lng']);
// }
// // echo $dom->saveXML();
}
?>