note 72549 deleted from function.date by felipe
| From: | felipe@php.net | Date: | Sat, 05 Jan 2008 01:56:28 +0000 |
| Subject: | note 72549 deleted from function.date by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134796@lists.php.net to get a copy of this message | ||
Note Submitter: kriswarner at solidaritymail dot com
----
Here's a useful bit of code - I took Mushy's code for
displaying a calendar, and added links for viewing previous
and next months, so you can go ahead or backwards as many months as you like, one month at a time.
Basically the top row is changed, and looks like:
December (prev) January February (next)
Here it is:
<?
//determining action, current month and year
$action = $_REQUEST['action'];
if (!$action) //first page, set current_month variable = current month
{
$current_month = date("m"); //value will change if the user changes the month they are
viewing
$current_year = date('Y');
}
else //if user selected to go to previous or next month, reset current_month variable
{
$current_month = $_REQUEST['current_month'];
$current_year = $_REQUEST['current_year'];
if ($action == 'prev')
{
$current_month = date('m', mktime(0, 0, 0, $current_month-1));
//if going from january to december, change year as well
if ($current_month == '12')
{
$current_year = date('Y', mktime(0, 0, 0, $current_month, 1, $current_year-1));
}
}
if ($action == 'next')
{
$current_month = date('m', mktime(0, 0, 0, $current_month+1));
//if going from december to january, change year as well
if ($current_month == '01')
{
$current_year = date('Y', mktime(0, 0, 0, $current_month, 1, $current_year+1));
}
}
}
$previous_month = date('F', mktime(0, 0, 0, $current_month-1, date("d"),
date("Y")));
$next_month = date('F', mktime(0, 0, 0, $current_month+1, date("d"),
date("Y")));
$theday = date(w, mktime(0, 0, 0, $current_month, 1, $current_year));
$daysinmonth = date("t", mktime(0, 0, 0, $current_month, 1, $current_year));
echo "<table border=1 width=90%>";
echo "<tr><td><a
href=$PHP_SELF?action=prev¤t_month=".$current_month."
¤t_year=".$current_year.">$previous_month</a></td>
<td colspan=5 align=center>".date('F Y', mktime(0, 0, 0, $current_month, 1,
$current_year))."</td>
<td><a href=$PHP_SELF?action=next¤t_month=".$current_month."
¤t_year=".$current_year.">$next_month</a></td></tr>";
echo "<tr>";
echo "<td>Sunday</td>";
echo "<td>Monday</td>";
echo "<td>Tuesday</td>";
echo "<td>Wednesday</td>";
echo "<td>Thursday</td>";
echo "<td>Friday</td>";
echo "<td>Saturday</td>";
echo "</tr>";
echo "<tr>";
for ($i=0;$i<$theday;$i++)
{
echo "<td> </td>";
}
for ($list_day=1;$list_day<=$daysinmonth;$list_day++)
{
echo "<td>" . $list_day . "</td>";
if ($theday == 6)
{
echo "</tr>";
echo "<tr>";
$theday = -1;
}
$theday++;
}
echo "</tr>";
echo "</table>";
?>