= '$first_day_of_month' AND driver.created_at < '$last_day_of_month' ) AS totalMonthlyDrivers, ( SELECT COUNT(*) FROM notesForDriverService WHERE notesForDriverService.createdAt >= '$first_day_of_month' AND notesForDriverService.createdAt < '$last_day_of_month' ) AS totalMonthlyCallingDrivers, ( SELECT COUNT(*) FROM notesForDriverService n JOIN driver d ON n.phone = d.phone WHERE n.createdAt >= '$first_day_of_month' AND n.createdAt < '$last_day_of_month' ) AS totalMonthlyMatchingNotes FROM date_series LEFT JOIN driver ON DATE(driver.created_at) = date_series.date LEFT JOIN notesForDriverService ON DATE( notesForDriverService.createdAt ) = date_series.date AND notesForDriverService.phone = driver.phone WHERE date_series.date >= '$first_day_of_month' AND date_series.date <= LEAST( CURDATE(), DATE_SUB('$last_day_of_month', INTERVAL 1 DAY)) GROUP BY date_series.date ORDER BY date_series.date DESC ; "; $stmt = $con->prepare($sql); $stmt->execute(); $car_locations = $stmt->fetchAll(PDO::FETCH_ASSOC); if ($car_locations) { // Print the car location data as JSON printSuccess($data = $car_locations); } else { // Print a failure message printFailure($message = "No car locations found"); } ?>