0

this is basically a followup from my previous question. My index page show the current year and quarter (eg: 2012 quarter 3, july, august, september) with all its contents. My problem might be simple to you but im a php noobie so im getting a hard time in figuring out the logic and how to do it. my pages are programmed dynamically in the sense that each data is stored in their proper month and year, my only problem is how to display dynamically the homepage based on the current quarter and year. thanks! This is my current code that i got from one of the answers in my previous question but it only changes the quarter dynamically.

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');
    }

}
4

2 回答 2

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..
        }
于 2012-08-09T09:34:10.363 回答
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

于 2012-08-09T10:15:17.550 回答