Help with Making a PHP calendar!
Posted: Wed Jul 16, 2008 4:42 pm
Hello,
I've been pulling my hair out trying to figure out how to do this....Hopefully someone can be of help =)...
Scenario:
I used this tutorial on making a calendar in PHP:
http://video.about.com/php/How-to-Creat ... lendar.htm
So, I need to make a PHP calendar....Easy enough right...but there one problem.
I made the "full" calendar but I need to modify the calendar to skip Sundays... This means that all Sundays are excluded when making table data.
So... the calendar would look like this:
July
Monday Tuesday Wednesday Thursday Friday Saturday
1 2 3 4 5
7 8 9 10 11 12
14 15 16 17 18 19
21 22 23 24 25 26
27 28 29 30 31
(sorry diagram isn't showing correctly...but the 1st is on Tues and so forth...)
Heres the php code that takes care of making the calendar....
Thanks,
Dauzy
I've been pulling my hair out trying to figure out how to do this....Hopefully someone can be of help =)...
Scenario:
I used this tutorial on making a calendar in PHP:
http://video.about.com/php/How-to-Creat ... lendar.htm
So, I need to make a PHP calendar....Easy enough right...but there one problem.
I made the "full" calendar but I need to modify the calendar to skip Sundays... This means that all Sundays are excluded when making table data.
So... the calendar would look like this:
July
Monday Tuesday Wednesday Thursday Friday Saturday
1 2 3 4 5
7 8 9 10 11 12
14 15 16 17 18 19
21 22 23 24 25 26
27 28 29 30 31
(sorry diagram isn't showing correctly...but the 1st is on Tues and so forth...)
Heres the php code that takes care of making the calendar....
Code: Select all
//Create a varible directory, which holds information that is taken from the scan() funtion.
$directory = scan();
//Variables for the day, month and year
$date = time ();
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
//Finds the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year);
//Calculates the day of the week that the first day is on
$day_of_week = date('D', $first_day);
//Sets the the day to a numerical value... Sun = 0...Sat = 6
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;
}
//Calculates the days in the month
$days_in_month = cal_days_in_month(0, $month, $year);
$day_count = 1;
//This while loop creates the blank spaces before the first day of the month.
while($blank > 0)
{
echo "<td></td>";
$blank = $blank-1;
$day_count++;
}
$day_num = 1;
//This while loop is used to create a table row and table ddta.
while($day_num <= $days_in_month)
{
//If the $day_num is included in $directory new table data with corresponded .jpg will be used.
if(in_array($day_num, $directory))
{
$event = "images/_calendar/July/calendar/".$day_num.".jpg";
echo '<td width="145px" height="145px" background="'.$event.'">'.$day_num.'</td>';
$day_num++;
$day_count++;
}
else
{
//If $day_num is not included in $directory new table data will be displayed with the default.jpg
echo '<td width="145px" height="145px" background="images/_calendar/July/calendar/default.jpg">'.$day_num.'</td>';
$day_num++;
$day_count++;
}
//This will ensure table row in the calendar will only have 7 days to it.
if($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
}
//This will ensure table row in the calendar will only have 7 days to it.
while($day_count > 1 && $day_count <= 7)
{
echo "<td></td>";
$day_count++;
}
Dauzy