2011-07-01 9 views
5

다음은 월 이름 + 연도가있는 선택 상자를 생성하는 PHP 코드입니다. 나는 타임 스탬프를 시작하고 타임 스탬프를 끝내는 루프에서 사용하고있는 타임 스탬프 두 개를 가지고있다.각 반복의 타임 스탬프에 한 달 추가

이제 예를 들어 내 시작 타임 스탬프가 01.07.2011 이고 루프에서 타임 스탬프에 30 일을 더한 다음 selectbox July이 두 번 표시됩니다. 그리고 31 일을 더하면 한 달이 될 수 있습니다.

각 반복마다 정확히 한 달을 추가 할 수있는 기능이 있습니까?

<select name="checkinMonth" class="selectform" id="checkinMonth" > 
<?php 
    for($month = $checkin_timestamp; $month <= $checkout_timestamp; $month += 30*60*60*24) { 
     $checkin_month = getdate($month); 
     $option_text = strftime("%B %Y",$month); 
     $option_value = strftime("%Y%m", $month); 
     $selected = ($checkin_selected == $option_value ? "selected='selected'" : ""); 

     echo "<option value='{$option_value}' {$selected}>{$option_text}</option>"; 
    } 
?> 
</select> 

답변

4

그리고 멋진 뭔가 더 자세한 경우,이 시도 :

$tmp_year = date("Y", $month); 
$tmp_month = date("m", $month); 
$tmp_day = date("d", $month); 
$tmp_hour = date("H", $month); 
$tmp_min = date("m", $month); 
$tmp_sec = date("s", $month); 

$month = mktime($tmp_hour, $tmp_minute, $tmp_second, $tmp_month + 1, $tmp_day, $tmp_year); 

을 당신이해야합니다 생각 for 절에 적합하게하기 위해 함수에 넣는 것 : P

관련 문제