Tutorials
Next month calendar
-
Next month calendar
Posted on November 19, 2003
Written by
Louise (view more by Louise)
Comments (0)
Filed under Scripts: PHPCalendar, Tutorials
Here’s what you need to do in order to show next month’s calendar.
Create a new file, called, for instance, nextmonth.php. Paste the following code into it:
<?php
require("calc.php");
require("config.php");
$today_day = date("d");
$today_month = date("m");
$today_year = date("Y");
if(empty($year) || empty($month))
{
// get current year, month and day
$year = Date_Calc::dateNow("%Y");
$month = $today_month + 1;
$day = "01";
}
// get month structure for generating calendar
$month_cal = Date_Calc::getCalendarMonth($month,$year,"%E");
$view = "month";
?>
<CENTER>
<TABLE border=0 cellspacing=1>
<TR>
<TD colspan=7 align=center>
<?php echo Date_Calc::dateFormat($day,$month,$year,"<b>%B</b>%n"); ?>
</TD>
</TR>
<TR>
<TH>S</TH>
<TH>M</TH>
<TH>T</TH>
<TH>W</TH>
<TH>T</TH>
<TH>F</TH>
<TH>S</TH>
</TR>
<?
$curr_day = Date_Calc::dateNow("%Y%m%d");
// loop through each week of the calendar month
for($row = 0; $row < count($month_cal); $row++)
{
echo "<TR>n";
// loop through each day of the current week
for($col=0; $col < 7; $col++)
{
if(Date_Calc::daysToDate($month_cal[$row][$col],"%m") == $month)
{
$monthday = Date_Calc::daysToDate($month_cal[$row][$col],"%d");
$query="SELECT * FROM $table WHERE ( month = $month AND year = $today_year AND day = $monthday ) OR ( month = $month AND day = $monthday AND year = '0')";
$result=mysql_query($query);
$num=mysql_numrows($result);
if ($num == '0'){
echo "<TD>"
.Date_Calc::daysToDate($month_cal[$row][$col],"%d")
."</TD>n";
} else { ?>
<TD><A HREF="#" TITLE="<? $i=0; while ($i < $num) { $thing=mysql_result($result,$i,"thing"); if ($i == '0') { echo ""; } else { echo " and "; } ?><?=$thing?>
<? ++$i;
}
?>
">
<? echo ""
.Date_Calc::daysToDate($month_cal[$row][$col],"%d")
."n";
?>
</A></TD>
<? }
}
else
{
echo "<TD> </TD>n";
}
}
echo "</TR>n";
}
?>
<tr><td colspan="7">Powered by: <a href="http://codegrrl.com">PHPCalendar</a></td></tr>
</TABLE>
</CENTER>
Upload it to the same folder as your other calendar files, and write a include wherever you want it to show!
Comments
Comments are closed for this entry.