-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.php
More file actions
33 lines (27 loc) · 835 Bytes
/
display.php
File metadata and controls
33 lines (27 loc) · 835 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
32
33
<?php
// Database connection
$con = mysqli_connect("localhost", "root", "423301", "mini");
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
// Fetch all turf records
$result = $con->query("SELECT * FROM turf ORDER BY id DESC");
// Prepare output
$output = "";
while ($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($output != "") {
$output .= ",";
}
$output .= '{"id":"' . $rs["id"] . '",';
$output .= '"turf_name":"' . $rs["turf_name"] . '",';
$output .= '"location":"' . $rs["location"] . '",';
$output .= '"price":"' . $rs["price"] . '",';
$output .= '"availability":"' . $rs["availability"] . '"}';
}
$output = '{"records":[' . $output . ']}';
// Close connection
$con->close();
// Output JSON
echo ($output);
?>