Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将值if语句传递给另一个if语句_Php_Html_Date_Next - Fatal编程技术网

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

Php 将值if语句传递给另一个if语句,php,html,date,next,Php,Html,Date,Next,在我的系统中有一个日历,在日历顶部有两个按钮“下一个”和“上一个”,用于获取下一个月的年份和上一个月的年份。 当前月份为2015年11月。我想要的是,如果我单击“下一步”按钮,它将转到2015年12月的下一个月,如果我单击“上一步”按钮,它将返回到2015年11月的当前月份。现在发生的情况是,如果我单击“下一步”按钮,则月份年份为2015年12月,但如果我单击“上一步”按钮,则月份年份为2015年10月[从当前月份年份(2015年11月)减去1,但从2015年12月起不减去1] 有办法解决这个问

在我的系统中有一个日历,在日历顶部有两个按钮“下一个”和“上一个”,用于获取下一个月的年份和上一个月的年份。 当前月份为2015年11月。我想要的是,如果我单击“下一步”按钮,它将转到2015年12月的下一个月,如果我单击“上一步”按钮,它将返回到2015年11月的当前月份。现在发生的情况是,如果我单击“下一步”按钮,则月份年份为2015年12月,但如果我单击“上一步”按钮,则月份年份为2015年10月[从当前月份年份(2015年11月)减去1,但从2015年12月起不减去1]

有办法解决这个问题吗

我只知道将值从第一个语句
(isset($\u POST['next'))传递到第二个if语句
(isset($\u POST['previous'))

这是我的php代码:

/*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']);
}

这是您的问题
$currentmonthyyyyyymm=date('Y-m')您需要根据按下的内容进行设置。换句话说,它根本不需要是当前月份,而是所选月份,或者如果未选择任何月份,则当前月份
$currentmonthyyyyymm=isset($\u POST['selectedDate'])?日期($Y-m',标准时间($U POST['selectedDate']):日期($Y-m')您必须发布所选日期。好的,如果单击“下一步”按钮,如何将第一个if语句中的值$NextMonthyyyymm传递给第二个if语句?因为我需要在第二个if语句中使用该值来执行前面提到的递减,
$currentmonthyyyyymm=date('Y-m')
应该有一个“默认”(加载时)设置,这就是您所拥有的设置,然后在用户单击next或previous时可以进行更改。今天的日期应该等于当前选择的日期。我认为,可能所有默认的今天日期都应该具有这种能力(只需快速查看您的脚本)