2012-08-09 127 views
0

這基本上是我上一個問題的後續內容。我的索引頁面顯示當前的年份和季度(例如:2012年第3季度,7月,8月,9月)及其所有內容。我的問題可能對你很簡單,但我是一個PHP noobie,所以我很難弄清楚邏輯和如何去做。我的頁面是動態編程的,因爲每個數據都存儲在適當的月份和年份中,唯一的問題是如何根據當前季度和年份動態顯示主頁。謝謝!這是我目前的代碼,我從我之前的問題中的一個答案中得到,但它只是動態地改變了季度。根據當前年份和季度顯示索引頁面

if(!isset($_GET['quarter']) && !isset($_GET['year'])){ 
    $now = new DateTime(); 
    $month = (int)$now->format("m"); 


    if ($month >= 1 AND $month <= 3) { 
     include_once('/firstq2012.php'); 
    } 
    elseif ($month >= 4 AND $month <= 6) { 
     include_once('/secondq2012.php'); 
    } 
    elseif ($month >= 7 AND $month <= 9) { 
     include_once('/thirdq2012.php'); 
    } 
    else { 
     include_once('/fourthq2012.php'); 
    } 

} 
+0

你在哪裏存儲數據?你能給我格式嗎?我的意思是,它是一個數組還是什麼? – 2012-08-09 09:31:23

+0

不是數組先生。每個條目都是通過不同字段的表單輸入的 – jet 2012-08-09 10:05:36

回答

0
if(!isset($_GET['quarter']) && !isset($_GET['year'])){ 
     $now = new DateTime(); 
     $number_of_division_per_year = 4;//you can use 1,2,4,6,12 
     $q = (($now->format("m")/($number_of_division_per_year-1))+1).'_'; 
     include_once('/'.$q.'2012.php'); 
     //now $q = 3(representing 3rd quarter); 
     //your file names should be like this 1_2012.php(first quarter), 
     //2_2012.php(second quarter) etc.. 
     } 
0

既然你想讓它也逐年展現動態,你可以這樣做:

if (!isset($_GET['quarter']) && !isset($_GET['year'])) { 
    $now = new DateTime(); 
    $quarter = (int)$now->format('m')/4; 
    $year = (int)$now->format('YYYY'); 
    $filename = '/'.$quarter.'-'.$year.'.php'; 
    include_once($filename); 
} 

但文件名應該是這樣的:

4-2011。 php,1-2012.php,2-2012.php,3-2012.php,4-2012.php

+0

實際先生,我沒有多個文件,如1-2013.php,1-2014.php。我每個季度只有一個文件,內容根據$ _GET ['year']而變化。有多個文件不會使它動態。 「-2012」意味着什麼。其通常的文件名。對困惑感到抱歉。 – jet 2012-08-09 10:27:42

相關問題