note 94472 added to function.cal-days-in-month
| From: | gayatrivb at gmail dot com | Date: | Sat, 07 Nov 2009 10:20:08 +0000 |
| Subject: | note 94472 added to function.cal-days-in-month | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162468@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 92.48.74.199
Probable Submitter: 87.114.203.238
----
Manual Page -- http://www.php.net/manual/en/function.cal-days-in-month.php
Edit -- https://master.php.net/note/edit/94472
Del: integrated -- https://master.php.net/note/delete/94472/integrated
Del: useless -- https://master.php.net/note/delete/94472/useless
Del: bad code -- https://master.php.net/note/delete/94472/bad+code
Del: spam -- https://master.php.net/note/delete/94472/spam
Del: non-english -- https://master.php.net/note/delete/94472/non-english
Del: in docs -- https://master.php.net/note/delete/94472/in+docs
Del: other reasons-- https://master.php.net/note/delete/94472
Reject -- https://master.php.net/note/reject/94472
Search -- https://master.php.net/manage/user-notes.php