Easy Calendar Navigation with PHP

Submitted by:Jhon Brain

Date added:26 December, 2011

Category:PHP

Example PHP code to navigate calender in HTML pages

Tags: calendar navigation

Code Snippet:

<html> 
<head>
<title>Hello</title>
<link rel=stylesheet type="text/css" href="./styles/styles.css">
</head>
<body bgcolor="#FFFFE0">
<?php

$j = $j ? $j : date("Y",time());
$m = $m ? $m : date("n",time());
$d = $d ? $d : date("j",time());
$intDATE=(mktime(0,0,0,$m,$d,$j));
$upM=mktime(0,0,0,($m+1),1,$j);
$doM=mktime(0,0,0,($m-1),1,$j);

function get_mARRAY() {
global $intDATE;
global $d;
global $m;
global $j;
if (date("w",mktime(0,0,0,$m,1,$j))==2) { //if 1st of requested month is a monday -
start with first
$startDAY=mktime(0,0,0,$m,1,$j);
} else { //if not then we look for the last monday of
the previous month
$startDAY=mktime(0,0,0,$m,0-date("w",mktime(0,0,0,$m,1-1,$j)),$j);
}

for ($i=1;$i<=42;$i++) {

$marray[$i]=mktime(0,0,0,date("n",$startDAY),date("j",$startDAY)+$i,date
("Y",$startDAY));
}
return $marray;
}
$mARRAY=get_mARRAY();
?>
<table border="0">
<tr>
<td align="left">
<?php
echo '<a href="calnav.php?j=' . date
("Y",$doM) . '&m=' . date("n",$doM) . '&d=' . date("j",$doM) . '" target="navframe">';
echo '<img src="./images/mondo.gif" border=0>';
echo '</a>';
?>
</td>
<td colspan="5">
<p align="center"><font size="1"
face="Verdana" color="#000080">
<?php
echo date("F",$intDATE) . " " . date("Y",$intDATE);
?></font></p>
</td>
<td align="right">
<?php
echo '<a href="calnav.php?j=' . date("Y",$upM) . '&m=' . date
("n",$upM) . '&d=' . date("j",$upM) . '" target="navframe">';
echo '<img src="./images/monup.gif" border=0>';
echo '</a>';
?>
</font>?</td>

</tr>
<tr>
<td width=17 height=17 align="center" bgcolor="#000080">
<font color="#FFFFFF">
M
</font></td>
<td width=17 height=17 align="center" bgcolor="#000080">
<font color="#FFFFFF">
T
</font></td>
<td width=17 height=17 align="center" bgcolor="#000080">
<font color="#FFFFFF">
W
</font></td>
<td width=17 height=17 align="center" bgcolor="#000080">
<font color="#FFFFFF">
T
</font></td>
<td width=17 height=17 align="center" bgcolor="#000080">
<font color="#FFFFFF">
F
</font></td>
<td width=17 height=17 align="center" bgcolor="#000080">
<font color="#FFFFFF">
S
</font></td>
<td width=17 height=17 align="center" bgcolor="#000080">
<font color="#FFFFFF">
S
</font></td>
</tr>

<?php
$countDAYS=1;
for ($w=1;$w<=6;$w++) {
echo '<tr>';
for ($d=1;$d<=7;$d++) {
echo '<td height=15 align="center">';
if (((date("j",$mARRAY[$countDAYS])>7) & ($w==1)) | ((date
("j",$mARRAY[$countDAYS])<=14) & ($w>=5))) {

echo '<a href="calnav.php?j=' . date("Y",$mARRAY[$countDAYS]) . '&m=' .
date("n",$mARRAY[$countDAYS]) . '&d=' . date("j",$mARRAY[$countDAYS]) . '"
target="navframe" style="color:C0C0C0">';
echo date("j",$mARRAY[$countDAYS]);
echo '</a>';
} else {
if ($mARRAY[$countDAYS]==$intDATE) {
echo '<strong>';
}

echo '<a href="calnav.php?j=' . date("Y",$mARRAY[$countDAYS]) . '&m=' .
date("n",$mARRAY[$countDAYS]) . '&d=' . date("j",$mARRAY[$countDAYS]) . '"
target="navframe">';
echo date("j",$mARRAY[$countDAYS]);
echo '</a>';
if ($mARRAY[$countDAYS]==$intDATE) {
echo '</strong>';
}
}



echo '</td>';
$countDAYS=++$countDAYS;
}
echo '</tr>';
}
?>
</table>
</body>
</html>
 
 

Comments