commit
This commit is contained in:
90
kngil/bbs/mypage02.php
Normal file
90
kngil/bbs/mypage02.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once $_SERVER['DOCUMENT_ROOT'].'/kngil/bbs/db_conn.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($_SESSION['login'])) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['status' => 'error', 'message' => '로그인이 필요합니다.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (empty($_SESSION['mypage_verified'])) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['status' => 'error', 'message' => '마이페이지 인증이 필요합니다.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$userId = $_SESSION['login']['user_id'];
|
||||
|
||||
/* =========================
|
||||
페이징 파라미터
|
||||
========================= */
|
||||
$page = max(1, intval($_GET['page'] ?? 1));
|
||||
$pageSize = 5;
|
||||
$offset = ($page - 1) * $pageSize;
|
||||
|
||||
try {
|
||||
|
||||
/* =========================
|
||||
1. 내 정보
|
||||
========================= */
|
||||
$stmt = $pdo->prepare("SELECT * FROM kngil.sp_users_my_r(:user_id)");
|
||||
$stmt->execute([':user_id' => $userId]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$user) {
|
||||
echo json_encode(['status' => 'error', 'message' => '사용자 정보 없음']);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
2. 전체 건수
|
||||
========================= */
|
||||
$cntStmt = $pdo->prepare("
|
||||
SELECT COUNT(*)
|
||||
FROM kngil.use_history
|
||||
WHERE user_id = :user_id
|
||||
");
|
||||
$cntStmt->execute([':user_id' => $userId]);
|
||||
$totalCount = (int)$cntStmt->fetchColumn();
|
||||
|
||||
$totalPages = (int)ceil($totalCount / $pageSize);
|
||||
|
||||
/* =========================
|
||||
3. 현재 페이지 데이터
|
||||
========================= */
|
||||
$histStmt = $pdo->prepare("
|
||||
SELECT *
|
||||
FROM kngil.sp_users_my_history(:user_id)
|
||||
OFFSET :offset
|
||||
LIMIT :limit
|
||||
");
|
||||
$histStmt->bindValue(':user_id', $userId, PDO::PARAM_STR);
|
||||
$histStmt->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||
$histStmt->bindValue(':limit', $pageSize, PDO::PARAM_INT);
|
||||
$histStmt->execute();
|
||||
|
||||
$history = $histStmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'user' => $user,
|
||||
'history' => $history,
|
||||
'pagination' => [
|
||||
'page' => $page,
|
||||
'pageSize' => $pageSize,
|
||||
'totalCount' => $totalCount,
|
||||
'totalPages' => $totalPages
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => '서버 오류',
|
||||
'detail' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user