anime-backlog-list/php/check_completed_year.php

27 lines
735 B
PHP
Raw Normal View History

2025-01-07 12:23:54 +05:00
<?php
include_once 'db_connect.php';
$year = $_GET['year'];
$yearMap = [
'pre-2009' => -1,
're-watch' => -2,
'manga' => -3
];
$yearValue = $yearMap[$year] ?? (int)$year;
// Count total records and completed records for that year
$stmt = $conn->prepare("SELECT COUNT(*) AS total_records, SUM(is_completed) AS total_completed FROM anime_list WHERE year = :year");
$stmt->bindParam(':year', $yearValue, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$all_completed = false;
if ($row && $row['total_records'] > 0 && $row['total_completed'] == $row['total_records']) {
$all_completed = true;
}
header('Content-Type: application/json');
echo json_encode(['all_completed' => $all_completed]);