php前几个月

时间:2018-03-05 18:03:21

标签: php sql

我正在使用此代码访问前几个月的数据。然而,当它到达1月它停止并且不会持续到去年12月。我如何调整此代码以继续回到前几个月和几年。

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

1 个答案:

答案 0 :(得分:0)

我最后使用了发布用于日历的下一个和上一个按钮。这是一个很棒的日历,很容易使用。

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;
相关问题