簡體   English   中英

PHP的前幾個月

[英]php previous months years

我正在使用此代碼訪問前幾個月的數據。 但是,到一月份時它將停止,並且不會持續到上一年的十二月。 我將如何調整此代碼以繼續回到前幾個月和前幾年。

    $prev_date = date('Y-m', strtotime($date .' -1 month'));

我最終使用了發布用於日歷的下一個和上一個按鈕。 這是一個很棒的日歷,易於使用。

https://davidwalsh.name/php-event-calendar

$month = (int) (!empty($_GET['month']) ? $_GET['month'] : date('m'));
$year = (int)  (!empty($_GET['year']) ? $_GET['year'] : date('Y'));

/* "next month" control */
$next_month_link = '<a href="?month='.($month != 12 ? $month + 1 : 
1).'&year='.($month != 12 ? $year : $year + 1).'" class="control">Next Month 
>></a>';

/* "previous month" control */
$previous_month_link = '<a href="?month='.($month != 1 ? $month - 1 : 
12).'&year='.($month != 1 ? $year : $year - 1).'" class="control"><<    
Previous Month</a>';

/* bringing the controls together */
$controls = '<form 
method="get">'.$select_month_control.$select_year_control.' <input 
type="submit" name="submit" value="Go" />      '.$previous_month_link.'     
'.$next_month_link.' </form>';

echo $controls;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM