Jump to content

how to add dates from the prevoius / next month?


newb

Recommended Posts

How can i add dates from the previous / next month to the calendar for this calendar script? id like it to appear so its like:

 

28 29 30 31 1 2 3 4 5 6 etc.. then at the end 29 30 31 1 2 3 etc...

 

function av_calendar () {
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", 
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["sm"])) $_REQUEST["sm"] = date("n");
if (!isset($_REQUEST["sy"])) $_REQUEST["sy"] = date("Y");
$cMonth = $_REQUEST["sm"];
$cYear = $_REQUEST["sy"];

$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;

if ($prev_month == 0 ) {
	$prev_month = 12;
	$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
	$next_month = 1;
	$next_year = $cYear + 1;
}
//
$today = date('d');
echo '
	<div class="head">
	<h1>'.$monthNames[$cMonth-1].' '.$cYear.'</h1>
	</div>
	<div class="blockitem2">
<table width="100%" class="calendar" style="margin-left:-10px;" border="0" cellpadding="2" cellspacing="2">
<tr style="font-size:20px">
<th align="center"><strong>S</strong></th>
<th align="center"><strong>M</strong></th>
<th align="center"><strong>T</strong></th>
<th align="center"><strong>W</strong></th>
<th align="center"><strong>T</strong></th>
<th align="center"><strong>F</strong></th>
<th align="center"><strong>S</strong></th>
</tr> ';
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
	$sy = date("Y",$timestamp);
	$sm = date("m",$timestamp);
	$sd = date("d",$timestamp);


for ($i=0; $i<($maxday+$startday); $i++) {
$day = ($i - $startday + 1);


	if(($i % 7) == 0 ) { echo "<tr>\n"; }
	if($i < $startday) { echo "<td></td>\n";
	} else {
	$now = "$sy-$sm-$day 00:00:00";
	$then = "$sy-$sm-$day 23:59:59";
	$sql = "SELECT av_episodes.id,av_episodes.date FROM av_episodes WHERE date between UNIX_TIMESTAMP('$now') AND UNIX_TIMESTAMP('$then')";
	$query = exec_mysql_query($sql)  or die(mysql_error());
	$rows = mysql_num_rows($query);
	$nowurl = "$sy/$sm/$day/";

		if(!empty($rows)) {
		echo "<td class='dates' align='center' valign='middle' height='20px'><b><a href='".SITE_URL."updates/".$nowurl."'>". add_nulls($day) . "</a></b>";
		} else { 
		echo "<td class='datesInactive' align='center' valign='middle' height='20px'>". add_nulls($day) . "";
		}
		echo "</td>\n";





	if(($i % 7) == 6 ) {echo "</tr>\n";	}



}
}
echo '</table></div>
';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.