我有五个文件,即index.php
和first.php .. fourth.php
。
first.php
到fourth.php
表示年度日历,分为4个季度(每个文件3个月)。现在,我只需要在索引页面中显示当前季度。例如,自8月起,我的索引应显示third.php
,其中包含7月,8月和9月。简而言之,我需要使我的索引页面动态化。
这是我目前的代码,显然是静态的:
if(!isset($_GET['quarter']) && !isset($_GET['year'])){
include ('/thirdq2012.php');
}
另外,我该怎么测试呢?
编辑:问题已解决!我有另一个问题,在每个页面的顶部,我有一个下拉年按钮,从2011年,2012年,2013年切换。我的下一个问题是如何在不创建多个文件的情况下显示所选年份的特定季度?例如2011年1月1日(1月,2月,3月)包含用户输入的数据和其他值,但2012年第1季度不包含任何内容。我将如何从那里开启?答案 0 :(得分:7)
<?php
$now = new DateTime();
$month = (int)$now->format("m");
if ($month >= 1 AND $month <= 3) {
echo "First Quarter!";
}
elseif ($month >= 4 AND $month <= 6) {
echo "Second Quarter!";
}
elseif ($month >= 7 AND $month <= 9) {
echo "Third Quarter!";
}
else {
echo "Fourth Quarter!";
}