Friday, May 27, 2011

Create Calendar Showing Active Day, EN

So many tutorials about creating calendar using php, but not show the current date. Here are examples of programs that can show the active date. Obtained from various sources on the Internet and developed again (on active) with simple logic.

Here are examples of php code to create a simple calendar:

<html>
<head>

</head>
<body>
<?php
$monthnames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
?>

<?php
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
?>

<?php
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];

$prevyear = $cYear;
$nextyear = $cYear;
$prevmonth = $cMonth-1;
$nextmonth = $cMonth+1;

if ($prevmonth == 0 ) {
$prevmonth = 12;
$prevyear = $cYear - 1;
}
if ($nextmonth == 13 ) {
$nextmonth = 1;
$nextyear = $cYear + 1;
}
?>

<table width="100">
<tr align="center">
<td bgcolor="#AAAAAA" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left">&nbsp;&nbsp;<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prevmonth . "&year=" . $prevyear; ?>" style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $nextmonth . "&year=" . $nextyear; ?>" style="color:#FFFFFF">Next</a>&nbsp;&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="2" cellspacing="2" bgcolor="#eeeeee">
<tr align="center">
<td colspan="7" bgcolor="#AAAAAA" style="color:#FFFFFF"><strong><?php echo $monthnames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#AAAAAA" style="color:#FFFFFF"><strong>S</strong></td>
<td align="center" bgcolor="#AAAAAA" style="color:#FFFFFF"><strong>M</strong></td>
<td align="center" bgcolor="#AAAAAA" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#AAAAAA" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#AAAAAA" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#AAAAAA" style="color:#FFFFFF"><strong>F</strong></td>
<td align="center" bgcolor="#AAAAAA" style="color:#FFFFFF"><strong>S</strong></td>
</tr>


<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$skr=date('d');
for ($i=0; $i<($maxday+$startday); $i++) {
if($skr==$i-$startday+1){$font='#FF0000'; $strong='<strong>';}
else {$font='#000099'; $strong='';}
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else

echo "
<td align='center' valign='middle' height='20px'>".$strong."<font color='$font'>" .($i - $startday + 1) . "</font></strong></td>";
if(($i % 7) == 6 ) echo "</tr>";
}
?>

</table>
</td>
</tr>
</table>
</body>
</html>



This code to determine the current date by using simple logic:

for ($i=0; $i<($maxday+$startday); $i++) {
if($skr==$i-$startday+1){$font='#FF0000'; $strong='<strong>';}
else {$font='#000099'; $strong='';}

0 komentar:

Post a Comment

Thanks a lot for your attention...

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Web Hosting