// 페이지 및 카테고리 파라미터 $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $category_id = isset($_GET['category']) ? (int)$_GET['category'] : null; $per_page = 15; $offset = ($page - 1) * $per_page; try { $db = connectDB(); // 카테고리 목록 가져오기 $categories = $db->query("SELECT * FROM board_categories ORDER BY name")->fetchAll(); // 전체 게시글 수 계산 $count_sql = "SELECT COUNT(*) FROM board_posts"; if ($category_id) { $count_sql .= " WHERE category_id = :category_id"; $stmt = $db->prepare($count_sql); $stmt->execute(['category_id' => $category_id]); } else { $stmt = $db->query($count_sql); } $total_posts = $stmt->fetchColumn(); // 게시글 목록 가져오기 $sql = " SELECT p.*, c.name as category_name, u.username as author_name, (SELECT COUNT(*) FROM board_comments WHERE post_id = p.id) as comment_count FROM board_posts p JOIN board_categories c ON p.category_id = c.id JOIN users u ON p.author_id = u.id "; if ($category_id) { $sql .= " WHERE p.category_id = :category_id"; } $sql .= " ORDER BY p.created_at DESC LIMIT :offset, :per_page"; $stmt = $db->prepare($sql); if ($category_id) { $stmt->bindValue(':category_id', $category_id, PDO::PARAM_INT); } $stmt->bindValue(':offset', $offset, PDO::PARAM_INT); $stmt->bindValue(':per_page', $per_page, PDO::PARAM_INT); $stmt->execute(); $posts = $stmt->fetchAll(); // 페이지네이션 $total_pages = ceil($total_posts / $per_page); } catch (PDOException $e) { error_log($e->getMessage()); $error = "서버 오류가 발생했습니다."; }
Siwon illustration

Community Board

Welcome to our community board where members can freely share their thoughts, ideas, and engage in meaningful discussions about mathematics, science, and programming.

Board

All
No. Category Title Author Date Views
No posts found.