douci4026 2015-11-05 02:31
浏览 61

将值if if语句传递给另一个if语句PHP

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']);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失