-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget_keyword.php
More file actions
47 lines (38 loc) · 1003 Bytes
/
get_keyword.php
File metadata and controls
47 lines (38 loc) · 1003 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
42
43
44
45
46
47
<?php
require_once __DIR__ . '/db_connect.php';
header("Content-Type: application/json; charset=utf-8");
$sort = $_GET['sort'] ?? 'popular';
$orderBy = "participant_count DESC"; // 기본: 인기
if ($sort === 'recent') {
$orderBy = "k.created_at DESC";
}
$sql = "
SELECT
k.keyword_id AS id,
k.name,
k.question_count,
COUNT(DISTINCT kc.sender_id) AS participant_count,
k.created_at
FROM keywords k
LEFT JOIN keyword_chats kc
ON kc.keyword_id = k.keyword_id
GROUP BY k.keyword_id
ORDER BY $orderBy
LIMIT 10
";
$result = $conn->query($sql);
$keywords = [];
while ($row = $result->fetch_assoc()) {
$keywords[] = [
"id" => (int)$row["id"],
"name" => $row["name"],
"question_count" => (int)$row["question_count"],
"participant_count" => (int)$row["participant_count"],
"created_at" => $row["created_at"]
];
}
echo json_encode([
"success" => true,
"keywords" => $keywords
], JSON_UNESCAPED_UNICODE);
$conn->close();