Menampilkan Kalender Menggunakan PHP

Posted: Desember 7, 2012 in php

Tag PHP

<?php
define(“sehari”, (60*60*24));
if (!checkdate($_POST[‘month’], 1, $_POST[‘year’])) {
$nowArray = getdate();
$month = $nowArray[‘mon’];
$year = $nowArray[‘year’];
} else {
$month = $_POST[‘month’];
$year = $_POST[‘year’];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title>
<?php echo “Kalender: “.$firstDayArray[‘month’].
” “.$firstDayArray[‘year’] ?>
</title>
<head>
<body>
<form method=”post”
action=”<?php echo “$_SERVER[PHP_SELF]”; ?>”>
<select name=”month”>
<?php
$months = Array(“Januari”, “Februari”, “Maret”,
“April”, “Mei”, “Juni”, “Juli”, “Agustus”,
“September”, “Oktober”, “November”, “Desember”);
for ($x=1; $x <= count($months); $x++) {
echo “<option value=\”$x\””;
if ($x == $month) {
echo ” selected”;
}
echo “>”.$months[$x-1].””;
}
?>
</select>
<select name=”year”>
<?php
for ($x=1980; $x<=3000; $x++) {
echo “<option”;
if ($x == $year) {
echo ” selected”;
}
echo “>$x”;
}
?>
</select>
<input type=”submit” value=”Go!”>
</form>
<?php
$days = Array(“Mgu”, “Sen”, “Sel”,”Rab”, “Kam”, “Jum”, “Sab”);
echo “<table border=1 cellpadding=5><tr>”;
foreach ($days as $day) {
echo “<td bgcolor=\”#CCCCCC\” align=center>
<b>$day</b></td>”;
} for ($i=0; $i<(6*7); $i++) {
$dayArray = getdate($start);
if (($i % 7) == 0) {
if ($dayArray[‘mon’] != $month) {
break;
} else {
echo “</tr><tr>”;
}
} if ($i<$firstDayArray[‘wday’] ||
$dayArray[‘mon’] != $month) {
echo “<td>&nbsp;</td>”;
} else {
echo “<td>”.$dayArray[‘mday’].”
&nbsp;&nbsp; </td>”;
$start += sehari;
}
}
echo “</tr></table>”;
?>
</body>
</html>

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s