2010-03-29 112 views
1

下面是部分表格行,它將創建一行3列的行。 每邊兩列是鏈接,左邊是上一年,右邊是明年的鏈接。 中心是一月至十二月的鏈接。幫助,php日曆鏈接

當您點擊一個月份鏈接時,日曆會顯示您在當前日曆中點擊的月份。例如,日曆將默認打開當前月份和年份... 2010年3月。如果您點擊上一年(2009年),則會顯示當前的去年(2009年)月份(3月)......然後如果您單擊Jun,日曆將顯示六月的日曆當前所在的哪一年,即2009年六月。

我的問題是,我該怎麼做以下代碼來做這樣的事情。

$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"; 

在此先感謝。

編輯:

我首先應該提到這一點......只需要使用PHP。

謝謝。

+1

你能做什麼?你可以坐下來寫這個程序。無論如何,問題是什麼? – 2010-03-29 02:24:52

回答

1
+0

感謝Leo爲那個鏈接。我會做一些閱讀。 Col. Shrapnel,我的問題很簡單。如果你閱讀上面的示例代碼,我已經解釋了我想要的代碼。 再一次,剛剛接觸PHP,我只是使用我簡單的編程知識來創建代碼。這對你們中的一些人來說可能是一個蛋糕,但如果你只是告訴我坐下來寫這個節目,它不會幫助我。 :( 再次,我真的很感謝那些有和將會給出一些明智的建議 謝謝 – Ray 2010-03-29 03:03:53

+0

@Ray這個鏈接不會幫助你太多,而不要責怪答案,但看看你的問題,廣泛而不清楚。 – 2010-03-29 03:22:21

0

首先,你必須寫一個採取$年$月參數,繪製月曆日曆程序。

1

好的。這裏有一些提示,從

開始如上所述,你必須爲本月製作一個HTML日曆。 從打印出天數開始。 $num=date("t");會給你幾天。 所以,我希望您可以使用for循環,從1到$ num,在單獨的<td>標籤中打印每個數字。

接下來,嘗試在7天的塊中打破該列表。你可以用這個計數器。每次迭代都要增加它,一旦達到7,就加上</tr><tr>來打破一條線。

最後。您必須將此列表與本週的開始對齊。 date("w")會幫助你。

你能這樣做嗎?

1

也許它會更清晰,如果我有我的整個代碼,而不是我需要幫助的部分錶行。我已經創建了日曆。我只是想添加額外的行到該日曆,我可以點擊按年和月打開新的日曆。

如果你可以在瀏覽器上打開這個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>&nbsp;</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>&nbsp;</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>&nbsp;</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"] 
} 

現在的問題是...如何找出語法,並將其應用到我的原代碼?