note 94474 added to function.date
| From: | gayatrivb at gmail dot com | Date: | Sat, 07 Nov 2009 11:32:26 +0000 |
| Subject: | note 94474 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162470@lists.php.net to get a copy of this message | ||
<?php
/* Basic monthly calendar using '<<Prev' and 'Next>>' links - using
date()
*/
//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:
$mk_time = mktime(0,0,0,$today['mon'],1,$today['year']);
$colspan = date('N',$mk_time) - 1;
$weekday = $colspan;
$date = 1;
//$flag = 1;
$days_in_this_month = date('t',$mk_time);
//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></html>";
echo $html_form_str;
?>
You can choose to ignore the CSS part - just to get this running
--Gayatri
----
Server IP: 87.124.86.46
Probable Submitter: 87.114.203.238 (proxied: 87.114.203.238)
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/94474
Del: integrated -- https://master.php.net/note/delete/94474/integrated
Del: useless -- https://master.php.net/note/delete/94474/useless
Del: bad code -- https://master.php.net/note/delete/94474/bad+code
Del: spam -- https://master.php.net/note/delete/94474/spam
Del: non-english -- https://master.php.net/note/delete/94474/non-english
Del: in docs -- https://master.php.net/note/delete/94474/in+docs
Del: other reasons-- https://master.php.net/note/delete/94474
Reject -- https://master.php.net/note/reject/94474
Search -- https://master.php.net/manage/user-notes.php