prepare($sql); $stmh->execute(); $rows = $stmh->fetchAll(PDO::FETCH_ASSOC); // var_dump($rows); $chartData = []; foreach ($rows as $row) { $date = date("Y-m-d", strtotime($row['outdate'] ?? '')); $area1 = intval(trim($row['screen_m2'] ?? '')); // Ensure the value is numeric $area2 = intval(trim($row['slat_m2'] ?? '')); // Ensure the value is numeric // 해당 날짜 키가 없으면 0으로 초기화 if (!isset($chartData[$date])) { $chartData[$date] = 0; } $chartData[$date] += $area1 + $area2; } $jsonChartData = json_encode($chartData); } catch (PDOException $Exception) { print "오류: " . $Exception->getMessage(); } // var_dump($jsonChartData); ?>