forked from FindMEmory/FindMEmory_BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlikeQuestionList.php
More file actions
40 lines (33 loc) · 850 Bytes
/
likeQuestionList.php
File metadata and controls
40 lines (33 loc) · 850 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
<?php
require_once __DIR__ . '/db_connect.php';
header('Content-Type: application/json; charset=utf-8');
$user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
if ($user_id === 0) {
echo json_encode([
'success' => false,
'message' => 'user_id is required'
], JSON_UNESCAPED_UNICODE);
exit;
}
$sql = "
SELECT q.*
FROM questions q
JOIN question_likes l
ON q.question_id = l.question_id
WHERE l.user_id = $user_id
ORDER BY q.created_at DESC
";
$result = mysqli_query($conn, $sql);
$rows = [];
while ($row = mysqli_fetch_assoc($result)) {
$rows[] = array_map(function($v) {
return is_numeric($v) ? (int)$v : $v;
}, $row);
}
echo json_encode([
'success' => true,
'user_id' => $user_id,
'data' => $rows
], JSON_UNESCAPED_UNICODE);
mysqli_close($conn);
?>