【发布时间】:2023-03-19 14:54:01
【问题描述】:
我的问题:我不知道每次按下按钮时如何为变量 $i 添加 +7。我尝试使用 isset($_POST) 但你只能执行代码块以将 +7 添加到 $i 一旦我希望它是无限的。
下面的函数使用变量 $i 来确定你想要前进多少天,所以在我的例子中,当 $i = 7 时它会向前跳 7 天。这个功能很好用。
Timeschedule.php
// UPDATED: Used other function instead to show what desired results i want to achieve
public function getDate($i){
date_default_timezone_set('Europe/Amsterdam');
$datetime = new DateTime('today');
$datetime->modify('+' . $i . 'day');
$output = $datetime->format('d-m-Y');
return $output;
}
Orderstep_1.php
// This file includes timeschedule.php
include timeschedule.php
<input name="testbutton" class="testbutton" id="testbutton" type="submit" value="=>" />
现在我将 isset 与 post 一起使用,但它只能在页面上执行一次代码,我需要 i 不受限制。
if(isset($_POST['testbutton'])){
$i = $i + 7;
}
希望你们能把我送到正确的方向。
更新:
这段代码输出数据
$testObject = new TimeSchedule();
$date1 = $testObject->getDate(0); echo $date1;
输出结果
02-02-2015
点击按钮后我想要实现的输出
09-02-2015
16-02-2015
23-02-2015
etc...
【问题讨论】: