2012-04-23 2 views
2

PHPで現在の週と前週のドロップダウンナビゲーションを作成するにはどうすればいいですか? enter image description herePHPで過去4週間で作成されたドロップダウンを作成する方法

$date = '04/24/20012'; 
$ts = strtotime($date); 
$year = date('o', $ts); 
$week = date('W', $ts); 
for($i = 1; $i <= 7; $i++) {  
    $ts = strtotime($year.'W'.$week.$i); 
    print date("m/d/Y l", $ts) . "\n"; 
} 

このコードは、現在の週とドロップダウンを移入が、私が欲しいのは、前の4週間で、ドロップダウンを移入することです。

+0

$ date = '04/24/20012 '; $ ts = strtotime($ date); $ year =日付( 'o'、$ ts); $ week = date( 'W'、$ ts); $ ts = strtotime($ year.'W '。$ week。$ i); for($ i = 1; $ i <= 7; $ i ++); 印刷日( "m/d/Y l"、$ ts)。 "\ n"; } – tariq

+0

これは私に今週のことをもたらしますが、私が望むのは、前の4週間のリストを持つことです。 – tariq

+0

Tariq、あなたの質問にコードを追加してください。コメントではありません。読むのが難しく、人々は単にあなたの質問を渡します。 –

答えて

3
for ($i = 0; $i <= 4; $i++) 
{ 
    $weeks[] = date('m/d/Y', strtotime("-$i week", time())); 
} 

は与える:

array 
    0 => string '04/23/2012' (length=10) 
    1 => string '04/16/2012' (length=10) 
    2 => string '04/09/2012' (length=10) 
    3 => string '04/02/2012' (length=10) 
    4 => string '03/26/2012' (length=10) 

EDIT:をしたい場合は範囲​​は、このか:

for ($i = 0; $i <= 4; $i++) 
{ 
    $k = $i - 1; 
    $weeks[] = date('m/d/Y', strtotime("-$i week")) . ' - ' . 
       date('m/d/Y', strtotime("-$k week -1 day")); 
} 

を与える:

array 
    0 => string '04/23/2012 - 04/29/2012' (length=23) 
    1 => string '04/16/2012 - 04/22/2012' (length=23) 
    2 => string '04/09/2012 - 04/15/2012' (length=23) 
    3 => string '04/02/2012 - 04/08/2012' (length=23) 
    4 => string '03/26/2012 - 04/01/2012' (length=23) 
1

をあなたが主演したい場合月曜日にあなたの週(そして金曜日に終わり)あなたはこのような何かをすることができます:

$this_monday = strtotime('monday this week'); 
for ($i = 0; $i <= 4; $i++) 
{ 
    $k = $i - 1; 
    $weeks[] = date('m/d/Y', strtotime("-$i week", $this_monday)) . ' - ' . 
       date('m/d/Y', strtotime("-$k week -3 day", $this_monday)); 
} 
関連する問題