我目前正在从存储在 mysql 中的表单中获取日期时间,如下所示:
2013-03-18 09:00:00
但是,对于我正在构建的功能,我将一个事件插入到每周少于最后一周的日历中,除了开始日期已更改之外,插入基本上是复制的。
所以我得到这样的帖子:
if (isset($_POST['submit']))
{
echo $start = $_POST['startDT'].':00';
}
这行得通。仅放置一周的功能也是如此。我坚持的是在数周内复制它。
所以我的函数看起来像这样:
if ($allYear = "yes")
{
//Get Week in question - gives me the week number for that particular week
$startW = getStartWeek($start);
//It'll always be week 56 as the end week of the year
$endW = 56;
//while $i is less than or equal to 56, do it and add 1 to $i
for($i = $startW; $i <= $endw; $i++)
{
$query = $mysqli->prepare("INSERT INTO `Events`(`Start`, `End`, `Group`, `Unit`, `Type`, `Room`, `Lecturer`) VALUES ('$start', '$end', '$group', '$unit', '$type', '$room', '$lecturer')");
/*Here is where I'd add code to make the datetime, for example:
* $start is 2013-03-18 09:00:00 and $end is 2013-03-18 10:00:00
* I want $start in the next iteration to be 2013-03-25 09:00:00 and $end
* to be 2013-03-25 10:00:00. I then want $start to be 2013-04-01 09:00:00
* on the iteration after that. And so on.
*/
$start += strtotime("+1 week");
$end += strtotime("+1 week");
}
}