In my system have a calendar and at the top of the calendar have two button next and previous which is to get the next month year and previous month year. The current month year now is November 2015. What I want is If I click next button then it will go to the next month year December 2015 and if I click previous button then it will go back to the current month year which is November 2015. What happen now is, If i click next button then month year is December 2015, but if I click previous button the month year is October 2015 [decrements 1 from current month year(November 2015) but not decrements 1 from December 2015]
Any idea to solve this?
I only have idea which is to pass value from first statement (isset($_POST['next)']))
to the second if statement (isset($_POST['previous)']))
.
this is my php code:
/*increment decrement day month year with different format. check it*/
$CurrentMonthyyyymm = date('Y-m');
$month_year_Current = date('F Y');
$totday = date('t');
$totdayLastMonth= date('t', strtotime("-1 month", strtotime($CurrentMonthyyyymm))); // eg: 31
$totdayNextMonth= date('t', strtotime("+1 month ", strtotime($CurrentMonthyyyymm)));
$month_year_Last = date('F Y', strtotime("-1 month", strtotime($CurrentMonthyyyymm))); // eg: December 2014
$month_year_Next = date('F Y', strtotime("+1 month", strtotime($CurrentMonthyyyymm)));
$LastMonthyyyymm= date('Y-m', strtotime("-1 month", strtotime($CurrentMonthyyyymm))); // eg: 2014-12
$NextMonthyyyymm= date('Y-m', strtotime("+1 month ", strtotime($CurrentMonthyyyymm)));
/****** day month year next previous *****/
if (isset($_POST['next']))
{
$_SESSION['i'] = isset($_SESSION['i']) ? ++$_SESSION['i'] : 1;
$increment1 = $_SESSION['i'];
$totday= date('t', strtotime("+$increment1 month ", strtotime($CurrentMonthyyyymm)));
$month_year_Next = date('F Y', strtotime("+$increment1 month", strtotime($CurrentMonthyyyymm)));
$NextMonthyyyymm= date('Y-m', strtotime("+$increment1 month ", strtotime($CurrentMonthyyyymm)));
}else{
unset($_SESSION['i']);
}
// $NextMonthyyyymm;
if (isset($_POST['previous']))
{
$_SESSION['d'] = isset($_SESSION['d']) ? ++$_SESSION['d'] : 1;
$decrement1 = $_SESSION['d'];
$totday= date('t', strtotime("-$decrement1 month ", strtotime($CurrentMonthyyyymm)));
$month_year_Last = date('F Y', strtotime("-$decrement1 month", strtotime($CurrentMonthyyyymm)));
$LastMonthyyyymm= date('Y-m', strtotime("-$decrement1 month", strtotime($CurrentMonthyyyymm)));
}else{
unset($_SESSION['d']);
}