Simple PHP Calendar
In:
12Nov2009
I was searching today for a pre-made script for a simple php calendar and after a bit of search I've found this.
The code is a bit old, and the author's website doesn't seem to work anymore, so I decided to clean it up a bit.
You can see the result below.
- <?php
- // This gets today's date
- // This puts the day, month, and year in seperate variables
- // Here we generate the first day of the month
- //This gets us the month name
- //Here we find out what day of the week the first day of the month falls on
- //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
- switch($day_of_week) {
- case "Sun": $blank = 0; break;
- case "Mon": $blank = 1; break;
- case "Tue": $blank = 2; break;
- case "Wed": $blank = 3; break;
- case "Thu": $blank = 4; break;
- case "Fri": $blank = 5; break;
- case "Sat": $blank = 6; break;
- }
- // We then determine how many days are in the current month
- ?>
- <table cellpadding="0" cellspacing="0">
- <tr>
- </tr>
- <tr>
- <td>Sun</td>
- <td>Mon</td>
- <td>Tue</td>
- <td>Wed</td>
- <td>Thu</td>
- <td>Fri</td>
- <td>Sat</td>
- </tr>
- <?php $day_count = 1;// This counts the days in the week, up to 7 ?>
- <tr>
- <?php while ($blank > 0): //first we take care of those blank days ?>
- <td> </td> <?php $blank = $blank-1; $day_count++; ?>
- <?php endwhile; ?>
- <?php $day_num = 1; //sets the first day of the month to 1 ?>
- <?php while ($day_num <= $days_in_month): //count up the days, until we've done all of them in the month ?>
- <?php $day_num++; $day_count++; ?>
- <?php if ($day_count > 7): //Make sure we start a new row every week ?>
- </tr>
- <tr>
- <?php $day_count = 1; ?>
- <?php endif; ?>
- <?php endwhile; ?>
- <?php while ($day_count >1 && $day_count <=7): //Finaly we finish out the table with some blank details if needed ?>
- <td> </td>
- <?php $day_count++; ?>
- <?php endwhile; ?>
- </tr>
- </table>
Comments
Post new comment