forked from FindMEmory/FindMEmory_BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchMessage.php
More file actions
48 lines (40 loc) · 1.14 KB
/
fetchMessage.php
File metadata and controls
48 lines (40 loc) · 1.14 KB
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
<?php
require_once __DIR__ . '/db_connect.php';
header("Content-Type: application/json; charset=utf-8");
// GET 파라미터
$keyword_id = isset($_GET['keyword_id']) ? intval($_GET['keyword_id']) : 0;
$last_id = isset($_GET['last_id']) ? intval($_GET['last_id']) : 0;
if ($keyword_id == 0) {
echo json_encode([]);
exit;
}
// 메시지 가져오기
$sql = "
SELECT
c.chat_id,
c.keyword_id,
c.sender_id,
c.body,
c.created_at,
u.nickname AS user_name
FROM keyword_chats AS c
LEFT JOIN users AS u
ON c.sender_id = u.user_id
WHERE c.keyword_id = $keyword_id
AND c.chat_id > $last_id
ORDER BY c.chat_id ASC
";
$result = mysqli_query($conn, $sql);
$list = [];
while ($row = mysqli_fetch_assoc($result)) {
$list[] = [
"chat_id" => intval($row["chat_id"]),
"keyword_id" => intval($row["keyword_id"]),
"sender_id" => intval($row["sender_id"]),
"body" => $row["body"],
"created_at" => $row["created_at"],
"user_name" => $row["user_name"]
];
}
echo json_encode($list, JSON_UNESCAPED_UNICODE);
?>