- Monthly Calendar in PHP
- 02 Jan 2013 11:04:34 pm
- Last edited by Alex on 03 Jan 2013 07:10:53 pm; edited 2 times in total
I'm creating a web template for a photo calendar I want to create over the year. I really wanted to get the calendar photographed, printed and framed last year but lack of motivation and constant photography prevented this. This year, I'm hoping to help my motivation by creating a web calendar where the photos will display before displaying on my wall in countless picture frames.
Anyways, I've got what I think is the underlaying work laid out and I've already encountered an issue. I use two for loops to create the weeks and days of the calendar. 5 weeks of 7 days each for 35 days.
First for loops is for the weeks and the second loop for the days is located within. The HTML displays just fine when I have the week loop but when I add the day loop nothing displays. The page is white and the source as no content. I can remove the week loop and leave the day loop and still no content.
I'd prefer no critique on my methods (I know how static/dumb things are, especially for the days of the week) but only that I get this issue resolved at the moment. I'm going about this rather head-on with no tutorial trying to create a basic month calendar. After I get the calendar to generate I'll start focusing on getting it to start on the correct day of the week and so forth.
Code:
Anyways, I've got what I think is the underlaying work laid out and I've already encountered an issue. I use two for loops to create the weeks and days of the calendar. 5 weeks of 7 days each for 35 days.
First for loops is for the weeks and the second loop for the days is located within. The HTML displays just fine when I have the week loop but when I add the day loop nothing displays. The page is white and the source as no content. I can remove the week loop and leave the day loop and still no content.
I'd prefer no critique on my methods (I know how static/dumb things are, especially for the days of the week) but only that I get this issue resolved at the moment. I'm going about this rather head-on with no tutorial trying to create a basic month calendar. After I get the calendar to generate I'll start focusing on getting it to start on the correct day of the week and so forth.
Code:
<?php
error_reporting(E_ALL);
include('../../res/inc/header.php');
echo('<link rel="stylesheet" type="text/css" media="screen" title="Standard Style" href="../../res/css/calendar.css" >');
// Here we are getting everything we need to show a date and generate the calendar.
$month = date('F'); // January
$year = date('Y'); // 2013
$day = date('l'); // Wednesday
$date = date('d'); // 03
$suf = date('S'); // rd
$loop = date('t'); // How many days in current month
// Let's start by creating the box the calendar will be in and setting up the fixed days.
echo('<div class="tbox">');
echo('<h2>'. $day .' '. $month .' '. $date .'<sup>'. $suf .'</sup> '. $year .'</h2>');
echo('
<table id="calendar">
<tr>
<td colspan="7" class="month">' . $month . '</td>
<tr>
<td class="day">Sunday</td>
<td class="day">Monday</td>
<td class="day">Tuesday</td>
<td class="day">Wednesday</td>
<td class="day">Thursday</td>
<td class="day">Friday</td>
<td class="day">Saturday</td>
</tr>
');
// Setting $n to 0 because it'll serve as the day number.
$n = 0;
// Creating a for loop to create the weeks.
for ($w = 1; $w <= 5; $w++) {
echo('<tr class="week">');
/*
// Create another for loop for the days inside the week loop.
for ($d = 1; $d <=7; d++) {
// Increment $n by 1 each time through while it is still less then the number of days in the month.
if ($n<$loop) $n++;
echo('<td class="date">' . $n . '</td>');
} */
echo('</tr>
');
}
echo('</table>');
echo('</div>');
include('../../res/inc/footer.php');
?>