也許它會更清晰,如果我有我的整個代碼,而不是我需要幫助的部分錶行。我已經創建了日曆。我只是想添加額外的行到該日曆,我可以點擊按年和月打開新的日曆。
如果你可以在瀏覽器上打開這個php,你會注意到三列下的日曆下的鏈接。
左列是從當前顯示的年份開始的前一年打開的鏈接。
右欄是明年開放的鏈接,無論當前顯示哪一年。 中心列是從1月到12月每個月的鏈接,無論哪個月被點擊,它都會從當前「當前」顯示的年份中打開該月份日曆。
我希望這更清楚。我爲任何混淆而道歉。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>test</title>
<link rel="stylesheet" type="text/css" href="calendar.css" />
</head>
<body><center>
<?php
$date = time();
$Month = date('m', $date);
$Day = date('d', $date);
$Year = date('Y', $date);
/* Calendar layout*/
function calendar_layout($month,$day,$year)
{
/* This checkdate function displays "bool(true)" in the web page, so I commented out */
// var_dump(checkdate($month,$day,$year));
$MonthArray = array("January ","February ","March ","April ","May ","June ","July ","August ","September ","October ","Novembe r","December ");
$ThisMonth = $MonthArray[$month-1];
/* Creates table for calendar */
$Calendar = '<table border="1" cellpadding="5">';
$Header = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
/* Creates the first row print the Month and Year of this calendar */
$Calendar.= '<tr><td colspan="7">';
$Calendar.= '<div class="largewords">'.$ThisMonth.''.$year.'</div>';
$Calendar.= '</td></tr>';
/* Creates the second row for Week days and print the week days header */
$Calendar.= '<tr>
<td class="weekdays">'.implode('</td><td class="weekdays">',$Header).'</td>
</tr>';
/* Finds out and set how many blank days before 1st day */
$FirstDay = mktime(0,0,0,$month, 1, $year);
$DayOfWeek = date('D', $FirstDay);
switch($DayOfWeek){
case "Sun": $BlankDays = 0; break;
case "Mon": $BlankDays = 1; break;
case "Tue": $BlankDays = 2; break;
case "Wed": $BlankDays = 3; break;
case "Thu": $BlankDays = 4; break;
case "Fri": $BlankDays = 5; break;
case "Sat": $BlankDays = 6; break;
}
/* Finds out how many total days this month */
$DayInMonth = date('t',mktime(0,0,0,$month,1,$year));
$DayCounter = 0;
/* Creates the second row for first week */
$Calendar.= '<tr>';
/* Prints the blank spaces before day 1 */
while($DayCounter < $BlankDays)
{
$Calendar.= '<td> </td>';
$DayCounter++;
}
/* Starts printing dates */
for($PrintDay = 1; $PrintDay <= $DayInMonth; $PrintDay++):
$Calendar.= '<td class="eachday">';
$Calendar.= '<div class="numericdays">'.$PrintDay.'</div>';
$Calendar.= str_repeat('<p> </p>',2);
$Calendar.= '</td>';
if($BlankDays == 6):
$Calendar.= '</tr>';
if(($DayCounter+1) != $DayInMonth):
$Calendar.= '<tr>';
endif;
$BlankDays = -1;
$DayInWeek = 0;
endif;
$DayInWeek++; $BlankDays++; $DayCounter++;
endfor;
/* Prints blank spaces after the last day of the month */
if($DayInWeek < 8):
for($x = 1; $x <= (8 - $DayInWeek); $x++):
$Calendar.= '<td> </td>';
endfor;
endif;
/* Bottom row - links for other years and months */
$LastYear = getDate(mktime(0, 0, 0, $month, 1, $year-1));
$ThisYear = getDate(mktime(0, 0, 0, $month, 1, $year));
$NextYear = getDate(mktime(0, 0, 0, $month, 1, $year+1));
$LastY = $LastYear["year"];
$ThisY = $ThisYear["year"];
$NextY = $NextYear["year"];
/* Initializing the years range from 1970 to 2038 */
$MinYear = date("Y",mktime(0,0,0,1,1,1970));
$MaxYear = date("Y",mktime(0,0,0,1,1,2038));
$Calendar.= "</tr><tr><td>"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=" . $LastYear["year"] ."\"> $LastY </a></td>\n";
$Calendar.= "<td colspan=\"5\">"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[0] ."\">Jan.</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[1] ."\">Feb.</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[2] ."\">Mar.</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[3] ."\">Apr.</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[4] ."\">May</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[5] ."\">Jun.</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[6] ."\">Jul.</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[7] ."\">Aug.</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[8] ."\">Sep.</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[9] ."\">Oct.</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[10] ."\">Nov.</a> |
"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=".$ThisYear["year"]."&month=" . $MonthArray[11] ."\">Dec.</a>
</td>";
$Calendar.= "<td>"."<a "."href=\"".$_SERVER["PHP_SELF"]."?year=" . $NextYear["year"] ."\"> $NextY </a></td>\n";
}
/* Close the table */
$Calendar.= '</tr></table>';
return $Calendar;
}
echo '<a href="index.php">Today</a>', ' is: ', date('l, F jS Y');
echo "<br />";
echo "<br />";
echo calendar_layout("$Month","$Day","$Year");
?>
</center>
</body>
</html>
雖然我正在瀏覽Leo發佈的那個網站,但我發現了一些東西。 如果我理解正確,邏輯是編碼來檢查$ Month & $ Year變量是否設置或不是這個特定的部分。
所以我發現這一點,如果statment:
if(isset($_GET["Year"]))
{
use local system's year
}
else
{
$Year = $_GET["Year"]
}
現在的問題是...如何找出語法,並將其應用到我的原代碼?
你能做什麼?你可以坐下來寫這個程序。無論如何,問題是什麼? – 2010-03-29 02:24:52