prepare("SELECT * FROM schedule WHERE MONTH(date)=? AND YEAR(date)=? ORDER BY date ASC");
$stmt->execute([$month, $year]);
$rows = $stmt->fetchAll();
echo "Total rows: " . count($rows) . "
";
$eventsByDate = [];
foreach($rows as $r){
$d = $r['date'];
if(!isset($eventsByDate[$d])) $eventsByDate[$d] = [];
$eventsByDate[$d][] = $r;
}
echo "Dates with events: " . count($eventsByDate) . "
";
foreach($eventsByDate as $k => $v){
echo "$k => " . count($v) . " events: ";
foreach($v as $ev) echo htmlspecialchars($ev['kegiatan']) . ", ";
echo "
";
}
// Test sprintf match
$d = 21;
$ds = sprintf('%04d-%02d-%02d', $year, $month, $d);
echo "
Testing date key: $ds
";
echo "isset? " . (isset($eventsByDate[$ds]) ? "YES (".count($eventsByDate[$ds]).")" : "NO") . "
";
?>