';
try {
// output 테이블에서 num 컬럼 가져오기
$output_sql = "SELECT num FROM chandj.output";
$output_stmt = $pdo->prepare($output_sql);
$output_stmt->execute();
$output_results = $output_stmt->fetchAll(PDO::FETCH_ASSOC);
$total_rows = count($output_results);
$current_row = 0;
foreach ($output_results as $output_row) {
$output_num = $output_row['num'];
// make 테이블에서 outputnum이 같은 데이터를 가져오기
$make_sql = "SELECT `upnum`, `outputnum`, `num`, `text1`, `text2`, `text3`, `text4`, `text5`,
`ordercompany`, `callname`, `cutwidth`, `cutheight`, `number`, `printside`,
`direction`, `exititem`, `intervalnum`, `intervalnumsecond`, `memo`, `draw`,
`drawbottom1`, `drawbottom2`, `drawbottom3`, `exitinterval`, `cover`, `left_check`,
`mid_check`, `right_check`, `done_check`, `remain_check`
FROM chandj.make WHERE outputnum = :outputnum ORDER BY num ASC";
$make_stmt = $pdo->prepare($make_sql);
$make_stmt->bindParam(':outputnum', $output_num, PDO::PARAM_INT);
$make_stmt->execute();
$make_results = $make_stmt->fetchAll(PDO::FETCH_ASSOC);
$screenlist_data = [];
if ($make_stmt->rowCount() > 0) {
// 각 make 테이블의 행을 배열로 추가
foreach ($make_results as $make_row) {
// '띄우고'를 '띄고'로 변경
$drawbottom1 = str_replace('띄우고', '띄고', $make_row['drawbottom1']);
$drawbottom2 = str_replace('띄우고', '띄고', $make_row['drawbottom2']);
$drawbottom3 = str_replace('띄우고', '띄고', $make_row['drawbottom3']);
// draw 필드에서 파일명만 추출
preg_match('/
/', $make_row['draw'], $matches);
$draw = $matches[1] ?? '';
$screenlist_data[] = [
'upnum' => $make_row['upnum'],
'outputnum' => $make_row['outputnum'],
'num' => $make_row['num'],
'text1' => $make_row['text1'],
'text2' => $make_row['text2'],
'text3' => $make_row['text3'],
'text4' => $make_row['text4'],
'text5' => $make_row['text5'],
'ordercompany' => $make_row['ordercompany'],
'callname' => $make_row['callname'],
'cutwidth' => $make_row['cutwidth'],
'cutheight' => $make_row['cutheight'],
'number' => $make_row['number'],
'printside' => $make_row['printside'],
'direction' => $make_row['direction'],
'exititem' => $make_row['exititem'],
'intervalnum' => $make_row['intervalnum'],
'intervalnumsecond' => $make_row['intervalnumsecond'],
'memo' => $make_row['memo'],
'draw' => $draw,
'drawbottom1' => $drawbottom1,
'drawbottom2' => $drawbottom2,
'drawbottom3' => $drawbottom3,
'exitinterval' => $make_row['exitinterval'],
'cover' => $make_row['cover'],
'left_check' => $make_row['left_check'],
'mid_check' => $make_row['mid_check'],
'right_check' => $make_row['right_check'],
'done_check' => $make_row['done_check'],
'remain_check' => $make_row['remain_check']
];
}
}
// JSON으로 인코딩
$screenlist_json = json_encode($screenlist_data, JSON_UNESCAPED_UNICODE);
// output 테이블의 screenlist 업데이트
$update_sql = "UPDATE chandj.output SET screenlist = :screenlist WHERE num = :num";
$update_stmt = $pdo->prepare($update_sql);
$update_stmt->bindParam(':screenlist', $screenlist_json, PDO::PARAM_STR);
$update_stmt->bindParam(':num', $output_num, PDO::PARAM_INT);
if (!$update_stmt->execute()) {
echo "Error updating record for num $output_num: " . implode(", ", $update_stmt->errorInfo()) . "
";
}
// 진행 상황 출력
$current_row++;
echo "Processed rows: $current_row
";
if ($current_row % 100 == 0) {
echo "Processed $current_row of $total_rows rows
";
}
}
echo "Finished processing all records.";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>