A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: PHP Writing out a calendar with dates?

  1. #1
    Phantom Flasher... Markp.com's Avatar
    Join Date
    May 2000

    Thumbs up PHP Writing out a calendar with dates?

    Hi all, long time no see! Hope you're all good!

    I've started getting back in to PHP and I'm writing a calendar system.

    Now I've reached a point where I'm stuck and hopefully you can help!

    I'm writing out a calendar for a booking system which shows when a date is booked.

    So in the database I have a $StartDate and an $EndDate.

    I'm writing out my table with this code:
    for($i=0;$i<$days_in_month;$i++) {
    $week_number = date("Week W",mktime(0, 0, 0, $value, ($i+1), $year)); // Finds out the week of the year
    $weekday = date("l",mktime(0, 0, 0, $value, ($i+1), $year)); // What weekday it is today
    echo "<td title=\"$week_number: $weekday\"><a href=\"\">";
    if($weekday==date("l") & $i == (date("j")-1)) {
    echo "<!-- This is today -->";
    if($weekday=="Saturday"||$weekday=="Sunday") { // Is it a weekend?
    echo "<b>".($i+1)."</b> ";
    else {
    echo ($i+1)."</a></td>";
    Now I'm not sure what to do next.

    I need some sort of if statement, that starts a loop based on the $StartDate from the database then changes the background colour of all the dates after $StartDate till $EndDate is reached.

    The idea is that the calendar would have different background colours over the dates that are booked.

    Any ideas how I go about that?

  2. #2
    Registered User
    Join Date
    Feb 2001

    how about this approach (pseudocode!!)
    if($date > $StartDate && $date < $EndDate) $active = 1; else $active = 0;
    and later
    if($active) print "<font color=\"blue\">";
    if($active) print "</font>";

    I was putting the "pseudocode" there because you might be comparing dates with seconds, or dates with dates, etc.
    If your database returns the dates as seconds, a mktime() to convert the date-to-show into same units would make sense


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center