-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_latest_admin_message.php
More file actions
41 lines (33 loc) · 951 Bytes
/
get_latest_admin_message.php
File metadata and controls
41 lines (33 loc) · 951 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
34
35
36
37
38
39
40
41
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "lost_found_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$response = array();
$query = "SELECT DISTINCT sender_id, receiver_id, message, created_at
FROM admin_message
ORDER BY created_at DESC
LIMIT 1";
$result = $conn->query($query);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$response['success'] = true;
$response['messages'] = array(
array(
"sender_id" => $row['sender_id'],
"receiver_id" => $row['receiver_id'],
"message" => $row['message'],
"created_at" => $row['created_at']
)
);
} else {
$response['success'] = false;
$response['error'] = "No messages found.";
}
echo json_encode($response);
$conn->close();
?>