PHP周日用作条件链接

时间:2014-09-12 13:50:56

标签: php

使用this question我能够使用href链接基于当周的当前日期构建前进/后退功能。我还希望能够在特定的日期有一个href链接,所以你会注意到我添加了$link_7例如并建立了一个星期日的href。这里是疯狂的地方。你会注意到$link_7是指定的并且适用于星期日,但我必须在星期日将实际的href设为2。今天是星期五所以我认为我的例行程序正在做+2并抛弃价值。直接进入星期几时避免这种情况的最佳方法是什么?

if (array_key_exists('day', $_GET)) {
    $add_day = $_GET['day'];
} else {
    $add_day = 0;
}

$yesterday = $add_day - 1;
$tomorrow = $add_day + 1;

$link_yesterday = $_SERVER['PHP_SELF'] . '?day=' . $yesterday ;
$link_tomorrow  = $_SERVER['PHP_SELF'] . '?day=' . $tomorrow ;

$link_7  = $_SERVER['PHP_SELF'] . '?day=7' ;
$link_1  = $_SERVER['PHP_SELF'] . '?day=1' ;
$link_2  = $_SERVER['PHP_SELF'] . '?day=2' ;
$link_3  = $_SERVER['PHP_SELF'] . '?day=3' ;
$link_4  = $_SERVER['PHP_SELF'] . '?day=4' ;
$link_5  = $_SERVER['PHP_SELF'] . '?day=5' ;
$link_6  = $_SERVER['PHP_SELF'] . '?day=6' ;

$display_day = mktime(0, 0, 0, date("m")  , date("d") + $add_day, date("Y"));

$today = date('N', $display_day);
<a style="color:white" href="<?php echo $link_yesterday;?>">See Yesterday</a>
<a style="color:white" href="<?php echo $link_tomorrow;?>">See Tomorrow</a> | 
<a style="color:white" href="<?php echo $link_2;?>">Sunday</a>        
<a style="color:white" href="<?php echo $link_3;?>">Monday</a>
<a style="color:white" href="<?php echo $link_4;?>">Tuesday</a>
<a style="color:white" href="<?php echo $link_5;?>">Wednesday</a>
<a style="color:white" href="<?php echo $link_6;?>">Thursday</a>
<a style="color:white" href="<?php echo $link_7;?>">Friday</a>
<a style="color:white" href="<?php echo $link_1;?>">Saturday</a>
if( $today == 7) { ?>
<th class="WADAResultsTableHeader">Sunday</th>
<?php } elseif( $today == 1 ) { ?>
<th class="WADAResultsTableHeader">Monday</th>
<?php } elseif( $today == 2 ) { ?>
<th class="WADAResultsTableHeader">Tuesday</th>
<?php } elseif( $today == 3 ) { ?>
<th class="WADAResultsTableHeader">Wednesday</th>
<?php } elseif( $today == 4 ) { ?>
<th class="WADAResultsTableHeader">Thursday</th>
<?php } elseif( $today == 5 ) { ?>
<th class="WADAResultsTableHeader">Friday</th>
<?php } elseif( $today == 6 ) { ?>
<th class="WADAResultsTableHeader">Saturday</th>
<?php } ?>

0 个答案:

没有答案