Search the Community
Showing results for tags 'days and dates not working'.
-
I have a problem here, this script works with the exception of showing the correct days with the date Result can be seen at https://centurionphotographer.co.za/booking/ AI just gives me one different problem after another and I am not a good enough coder to solve the problem. // Number of months to display $monthsToShow = 3; // Get the current date and time $currentDate = date('Y-m-d'); // Calculate the start and end dates for the calendar $startDate = date('Y-m-d', strtotime($currentDate)); $endDate = date('Y-m-d', strtotime($currentDate . ' + ' . ($monthsToShow * 30) . ' days')); // Prepare the SQL statement to retrieve availability $availabilityQuery = $pdo->prepare(" SELECT avdate, COUNT(*) AS available_slots FROM availability WHERE avdate BETWEEN :start_date AND :end_date GROUP BY avdate "); // Prepare the SQL statement to retrieve bookings $bookingsQuery = $pdo->prepare(" SELECT bkdate, COUNT(*) AS booked_slots FROM bookings WHERE bkdate BETWEEN :start_date AND :end_date GROUP BY bkdate "); // Generate the calendar $currentMonth = ''; echo '<table>'; // Loop through each day within the specified range for ($date = $startDate; $date <= $endDate; $date = date('Y-m-d', strtotime($date . ' + 1 day'))) { $currentMonthOfDate = date('F Y', strtotime($date)); $dayOfWeek = date('w', strtotime($date)); // Check if a new month has started if ($currentMonth !== $currentMonthOfDate) { $currentMonth = $currentMonthOfDate; echo '<tr><th colspan="7">' . $currentMonth . '</th></tr>'; echo '<tr><th>Sunday</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th></tr>'; } // Check availability for the current date $availabilityQuery->bindParam(':start_date', $date); $availabilityQuery->bindParam(':end_date', $date); $availabilityQuery->execute(); $availabilityResult = $availabilityQuery->fetchAll(PDO::FETCH_ASSOC); // Check bookings for the current date $bookingsQuery->bindParam(':start_date', $date); $bookingsQuery->bindParam(':end_date', $date); $bookingsQuery->execute(); $bookingsResult = $bookingsQuery->fetchAll(PDO::FETCH_ASSOC); // Determine the class to apply based on availability if ($availabilityResult && $availabilityResult[0]['available_slots'] > 0) { $class = 'available'; $link = '<a href="timeslots.php?date=' . $availabilityResult[0]['avdate'] . '">Check available timeslots</a>'; } elseif ($bookingsResult && $bookingsResult[0]['booked_slots'] > 0) { $class = 'fully-booked'; $link = 'Fully Booked'; } else { $class = 'unavailable'; $link = ''; } // Output the date with the appropriate class and link echo '<td class="' . $class . '">' . $date . '<br>' . $link . '</td>'; // Start a new row after Saturday if ($dayOfWeek == 6) { echo '</tr><tr>'; } } echo '</table>';