forked from FindMEmory/FindMEmory_BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyQuestionList.php
More file actions
38 lines (31 loc) · 779 Bytes
/
myQuestionList.php
File metadata and controls
38 lines (31 loc) · 779 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
<?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 *
FROM questions
WHERE author_id = $user_id
ORDER BY 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);
?>