Waah udeh lama nih nggak ngeblog.
ehmmm………… enaknye ngapain yeh.
Oh iyeh, nih gue mo bagi-bagi sedikit codingan php buat nampilin calendar di situs loh!!!
nih preview-nya

and the code is below
//————————————-cut here—————————————-//
<?php
// function begin
function build_calendar($month,$year,$day) {
/* Declaring the variables */
// make an enumerator or array to the day’s name
$daysOfWeek = array(‘Su’,’Mo’,’Tu’,’We’,’Th’,’Fr’,’Sa’);
// get the first day of the month,
// returning number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.
$firstDayOfMonth = mktime(0,0,0,$month,1,$year); //mktime function(0,0,0,$month,$day,$year), return an unique int
// get number of days i this month
$noDays = date(‘t’,$firstDayOfMonth); //date function( string format ,[int timestamp] )
//getdate function ( [int timestamp] ),return an array of the time given
$dateComponents = getdate($firstDayOfMonth); //getdate function([int timestamp])
/*
Array return by the getdate function
(
[seconds] => xx –>Numeric representation of seconds 0 to 59
[minutes] => xx –>Numeric representation of minutes 0 to 59
[hours] => xx –>Numeric representation of hours 0 to 23
[mday] => xx –>Numeric representation of the day of the month 1 to 31
[wday] => xx –>Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
[mon] => xx –>Numeric representation of a month 1 through 12
[year] => xx –>A full numeric representation of a year, 4 digits Examples: 1999 or 2003
[yday] => xx –>Numeric representation of the day of the year 0 through 365
[weekday] => xx –>A full textual representation of the day of the week Sunday through Saturday
[month] => xx –>A full textual representation of a month, such as January through December
[0] => xxuniquexxx –> like mktime
)
*/
// get the day of week in the time given, look at array return by the getdate above
$dayOfWeek = $dateComponents[‘wday’];
// get the full textual representation of the month in the time given
$monthName = date(‘F’,mktime(0,0,0,$month,1,$year));
/* Computing the previous month. */
if($month == 1)
{
$mn=12;
$yn=$year-1;
} else {
$mn=$month-1;
$yn=$year;
}
$altn = date(‘F’,mktime(0,0,0,$mn,1,$yn));
/* Computing the next month. */
if($month == 12) {
$mn2=1;
$yn2=$year+1;
} else {
$mn2=$month+1;
$yn2=$year;
}
$altn2 = date(‘F’,mktime(0,0,0,$mn2,1,$yn2));
/* Calendar header: next and previous month links */
$calendar = “<table>”;
$calendar .= “<tr><td><a href=calendar.php?m=$mn&y=$yn&d=$day ><</a></td>”;
$calendar .=”<td colspan=5 align=center>$monthName, $year</td>”;
$calendar .=”<td><a href=calendar.php?m=$mn2&y=$yn2&d=$day >></a></td></tr>”;
$calendar .=”<tr>”;
/* Calendar header: Display the days of the week */
foreach($daysOfWeek as $day) {
$calendar .= “<td>$day</td>”;
}
$calendar .= “</tr>”;
$calendar .= “<tr>”;
$currentDay = 1;
// get current date
$datenow = getdate();
$monthnow = $datenow[‘mon’];
$yearnow = $datenow[‘year’];
$daynow = $datenow[‘mday’];
/* Fill in the beginning of the calendar body */
if ($dayOfWeek > 0) {
$calendar .= “<td colspan=’$dayOfWeek’> </td>”;
}
/* Generate the calendar body */
while ($currentDay <= $noDays) {
if ($dayOfWeek == 7) {
$dayOfWeek = 0;
$calendar .= “</tr><tr>”;
}
// check wether the day is today
if($year == $yearnow & $month == $monthnow & $currentDay == $daynow)
$calendar .= “<td style=’font-weight:bold; color:blue’>$currentDay</td>”;
else
$calendar .= “<td>$currentDay</td>”;
$currentDay++;
$dayOfWeek++;
}
/* Filling in the end of the calendar body */
if ($dayOfWeek != 7) {
$remainingDays = 7 – $dayOfWeek;
$calendar .= “<td colspan=’$remainingDays’> </td>”;
}
$calendar .= “</table>”;
return $calendar;
}
// end function
// if month, year and date are set then set it
if (isset($_GET[‘m’]) && isset($_GET[‘y’]) && isset($_GET[‘d’]))
{
$month = $_GET[‘m’];
$year = $_GET[‘y’];
$day = $_GET[‘d’];
} else
{
// if month, year and date aren’t set, then set the date to Now
$dateComponents = getdate();
$month = $dateComponents[‘mon’];
$year = $dateComponents[‘year’];
$day = $dateComponents[‘mday’];
}
echo build_calendar($month,$year,$day);
?>
//————————————-cut here—————————————-//
Nah, klo lo mo nyoba jangan lupa save dulu filenye dan kasih nama “calendar.php” , all in lowercase.
dont use another name, except you now how the code works.
But if you want to change the name of the file, you must change some code.
—->contoh<—-
misalnye loh mo’ kasih nama filenye jadi “filename.php”
1. cari di codingan tulisan
$calendar .= “<tr><td><a href=calendar.php?m=$mn&y=$yn&d=$day ><</a></td>”;
ganti jadi
$calendar .= “<tr><td><a href=filename.php?m=$mn&y=$yn&d=$day ><</a></td>”;
2. cari di codingan tulisan
$calendar .=”<td><a href=calendar.php?m=$mn2&y=$yn2&d=$day >></a></td></tr>”;
ganti jadi
$calendar .=”<td><a href=filename.php?m=$mn2&y=$yn2&d=$day >></a></td></tr>”;
nah abis tuh save deh dengan nama “filename.php”,inga’ inga’ extensionnye harus php.
Klo loh mo coba nih codingan di pc desktop or laptop loh, lo harus nginstal apache servernye terlebih dahulu biar code php-nye bisa di interprete.
nah untuk para master ane mohon maaf nih, ane cuman sekedar nge-share, nggak bermaksud sok ataupun sombong.
aah, udeh dulu ah soalnye udeh abis nih waktunye , nanti mama marah, he he he…
see you.