Jump to content

Search the Community

Showing results for tags 'days and dates not working'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. 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>';
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.