forked from thejanRajapaksha/SW-Tools-and-Practices
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_locations.php
More file actions
31 lines (25 loc) · 771 Bytes
/
fetch_locations.php
File metadata and controls
31 lines (25 loc) · 771 Bytes
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
<?php
// Assuming you're using MySQL and already have a connection
// Replace the database credentials and query with your own
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "accommodation";
$connection = mysqli_connect($host, $username, $password, $database);
if ($connection) {
$query = "SELECT * FROM advertisements";
$result = mysqli_query($connection, $query);
$markers = array();
while ($row = mysqli_fetch_assoc($result)) {
$markers[] = array(
'lat' => $row['latitude'],
'lng' => $row['lngitude']
);
}
header('Content-Type: application/json');
echo json_encode($markers);
mysqli_close($connection);
} else {
echo "Failed to connect to the database.";
}
?>