note 94472 deleted from function.cal-days-in-month by danbrown
| From: | danbrown@php.net | Date: | Sat, 07 Nov 2009 14:46:43 +0000 |
| Subject: | note 94472 deleted from function.cal-days-in-month by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162481@lists.php.net to get a copy of this message | ||
Note Submitter: gayatrivb at gmail dot com
----
Here's another simple(r) calendar:
<?php
/* Basic Calendar
*/
//we define index of the month we want to show as $i
$i = $_GET['i'];
if(! $i){
$i = 0;
}
//previous month to current
$prev_link_i = $i -1;
//next month to current
$next_link_i = $i +1;
//Get date for the month to be displayed
$today = getdate(time() + ($i * 30*24*60*60));
$cal_title = $today['month']." ". $today['year'];
// we need to combine those cells of the calendar, which would be in earlier month,
// so find out how many we need to combine:
$colspan = date('N', mktime(0,0,0,$today['mon'],1,$today['year'])) -
1;
$weekday = $colspan;
$date = 1;
//$flag = 1;
$days_in_this_month =
date('t',mktime(0,0,0,$today['mon'],1,$today['year']));
//Prepare our form:
$html_form_str = "<html><head><title>My Calendar</title>".
"<link rel='stylesheet' href='calendar.css'
type='text/css' media='screen' />".
"</head>";
$html_form_str.= "<body id='calendar'><table
id='table'><tr>";
$html_form_str.= "<th align='left' id='prev'><a
href=".$_SERVER['PHP_SELF']."?i=".$prev_link_i."> Prev
</a></th>";
$html_form_str.= "<th align='center' colspan='5'
id='caption'>".$cal_title."</th>";
$html_form_str.= "<th align='right' id='next'><a
href=".$_SERVER['PHP_SELF']."?i=".$next_link_i."> Next
</a></th></tr>";
$html_form_str.= "<tr><td>Mon </td><td>Tue </td><td>Wed
</td><td>Thu </td><td> Fri </td><td>Sat </td><td>Sun
</td></tr>";
if($colspan != 0){ // for correct indentation
$html_form_str.= "<td colspan='".$colspan."'> </td>";
}
while($weekday < 7){
$html_form_str.= "<td id='td-content'>".$date."</td>";
$weekday++;
$date++;
if($weekday == 7) {
break;
}
}
while($date <= $days_in_this_month){
$html_form_str.="<tr>";
$weekday = 0;
while($weekday < 7) {
$html_form_str.= "<td
id='td-content'>".$date."</td>";
$weekday++;
$date++;
if(($weekday == 7)||
($date > $days_in_this_month)) {
break;
}
}
$html_form_str.="</tr>";
}
$html_form_str .= "</table></body>";
echo $html_form_str;
?>
You can choose not to use the CSS part - just to display the calendar with the prev and next links.