Initial commit: 교육 프로젝트 배포
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/bbs/db_conn.php';
|
||||
|
||||
$currentYear = (int) date('Y');
|
||||
$currentMonth = (int) date('m');
|
||||
$currentQuarterNum = (int) ceil($currentMonth / 3);
|
||||
$currentQuarterCode = sprintf('CA200Q%02d', $currentQuarterNum);
|
||||
|
||||
echo "=== 정규식 테스트 ===\n";
|
||||
|
||||
// edu_learning_goals에서 goal_code 가져오기
|
||||
$stmt = db_conn()->prepare(
|
||||
"SELECT goal_code FROM edu_learning_goals
|
||||
WHERE is_active = '1'
|
||||
AND base_year = ?
|
||||
AND quarter = ?
|
||||
ORDER BY goal_code ASC"
|
||||
);
|
||||
$stmt->execute([(string)$currentYear, $currentQuarterCode]);
|
||||
$goalRows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$goalCodeById = [];
|
||||
foreach ($goalRows as $goalRow) {
|
||||
$goalCode = (string)($goalRow['goal_code'] ?? '');
|
||||
echo "Goal Code: '$goalCode'\n";
|
||||
|
||||
if (!preg_match('/-(\d{3})$/', $goalCode, $m)) {
|
||||
echo " 정규식 매칭 실패!\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$goalId = (int)$m[1];
|
||||
echo " 추출된 ID: $goalId\n";
|
||||
|
||||
if ($goalId >= 1 && $goalId <= 6) {
|
||||
$goalCodeById[$goalId] = $goalCode;
|
||||
echo " 매핑됨: $goalId => $goalCode\n";
|
||||
} else {
|
||||
echo " 범위 초과\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "\n최종 \$goalCodeById:\n";
|
||||
print_r($goalCodeById);
|
||||
|
||||
echo "\n=== edu_contents 조회 테스트 ===\n";
|
||||
$goalCodes = array_values(array_unique(array_filter($goalCodeById)));
|
||||
echo "조회할 goal_codes: " . json_encode($goalCodes) . "\n";
|
||||
|
||||
if (count($goalCodes) > 0) {
|
||||
$placeholders = implode(',', array_fill(0, count($goalCodes), '?'));
|
||||
$sql = "SELECT content_id, goal_code, title FROM edu_contents
|
||||
WHERE is_active = '1'
|
||||
AND goal_code IN ($placeholders)
|
||||
LIMIT 10";
|
||||
echo "SQL: $sql\n";
|
||||
|
||||
$stmtBooks = db_conn()->prepare($sql);
|
||||
$stmtBooks->execute($goalCodes);
|
||||
$bookRows = $stmtBooks->fetchAll(PDO::FETCH_ASSOC);
|
||||
echo "결과: " . count($bookRows) . "개\n";
|
||||
foreach ($bookRows as $row) {
|
||||
echo json_encode($row) . "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user