gpt4 book ai didi

php - 循环插入每周的时间表

转载 作者:行者123 更新时间:2023-11-29 09:05:48 25 4
gpt4 key购买 nike

我已经使用 listmailpro 设置了计划电子邮件脚本。我需要安排在接下来的几年中每月的每个星期一发送一封电子邮件。下面的例子展示了我想要实现的目标。我如何编写一个快速的 PHP 脚本来为我插入时间表,并更改每次插入的日期?

INSERT INTO `lm_schedule` (`id`, `type`, `date`, `subject`, `message`, `htmessage`, `fattach`, `list`) VALUES
('', 'm', '2011-08-15', 'Test weekly email (!date2)', 'email text', 'email body', '', '1'),
('', 'm', '2011-08-22', 'Test weekly email (!date2)', 'email text', 'email body', '', '1'),
('', 'm', '2011-08-29', 'Test weekly email (!date2)', 'email text', 'email body', '', '1'),
('', 'm', '2011-09-05', 'Test weekly email (!date2)', 'email text', 'email body', '', '1');

最佳答案

未经测试,但应该给出一个粗略的想法:

$init = strtotime('2011-08-15');
$stop = strtotime('2013-08-15');
$step = 604800;

switch (date('w', $init)) {
case 0:
$correction = 1;
break;
case 1:
$correction = 0;
break;
case 2:
$correction = 6;
break;
case 3:
$correction = 5;
break;
case 4:
$correction = 4;
break;
case 5:
$correction = 3;
break;
case 6:
$correction = 2;
break;
}
$init += $correction * $step;

$qry = 'INSERT INTO `lm_schedule` (`id`, `type`, `date`, `subject`, `message`, `htmessage`, `fattach`, `list`) VALUES (';
$dates = array();

for ($timestamp = $init; $timestamp < $stop; $timestamp += $step) {
$dates[] = ' ... ' . date('Y-m-d', $timestamp) . ' ... ';
}

$qry .= implode('),(', $dates) . ');';

关于php - 循环插入每周的时间表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7063964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com