我想知道如何安排动态(自动填充数据)功能在保存的时间每天自动运行?
假设我有一个表单,一旦单击该按钮,它就会将数据发送到函数,该函数会发布数据.我只想自动化,这样我就不必按下按钮了.
foreach($Class->retrieveData as $data)
{
'.$data['name'].'
'.$data['description'].'
}
?>
现在,表单将数据传递给函数.
if(isset($_POST['post_data'])) // if post_data button is clicked then it runs myFunction()
{
myFunction();
}
myFunction()
{
$name = $_POST['name'];
$description = $_POST['description'];
}
我尝试了以下操作,但问题是Cron Job只能运行整个.php文件,而我正在检索从MySQL运行的已保存时间.
foreach($Class->getTime() as $timeData)
{
$timeHour = $timeData['timeHour'];
$timeMinute = $timeData['timeMinute'];
$hourMin = date('H:i');
$timeData = ''.$timeHour.':'.$timeMinute.'';
if($hourMin == $timeData)
{
run myFunction.
}
}
$hourMin是当前小时:分钟,它与从Mysql自动运行的已保存时间相匹配.因此,如果$hourMin == $timeData,那么该函数将运行.
如果$hourMin等于$timeData,如何运行Cron Job来自动运行myFunction()?
所以…
List 1 = is to be runned at 10am
List 2 = is to be runned at 12pm
List 3 = is to be runned at 2pm
上午10点,下午12点,下午2点是从MySQL检索但是基于每个列表ID的$timeHour和$timeMinute.
编辑
@randomSeed,
1) I can schedule cron jobs.
2) $name and $description will all be arrays, so the following is what I am trying to accomplish.
$name = array(
'Jon',
'Steven',
'Carter'
);
$description = array(
'Jon is a great person.',
'Steven has an outgoing character.',
'Carter is a horrible person.'
);
如果预定的时间是正确的,我想解析$name和$description中的第一个数组.
在数据库中,我有以下内容
postDataTime table
+----+---------+----------+------------+--------+
| iD | timeDay | timeHour | timeMinute | postiD |
+--------------------------------------+--------+
| 1 | * | 9 | 0 | 21 |
|----|---------|----------|------------|--------|
| 2 | * | 10 | 30 | 22 |
|----|---------|----------|------------|--------|
| 3 | * | 11 | 0 | 23 |
+----|---------+----------+------------+--------+
iD = auto incremented on upload.
timeDay = * is everyday (cron job style)
timeHour = Hour of the day to run the script
timeMinute = minute of the hour to run script
postiD = this is the id of the post that is located in another table (n+1 relationship)
if(time() == 10:30(time from MySQL postiD = 22))
{
// run myFunction with the data that is retrieved for that time ex:
$postiD = '22';
$name = 'Steven';
$description = 'Steven has an outgoing character.';
// the above is what will be in the $_POST from the form and will be
// sent to the myFunction()
}
我只想根据保存到MySQL的时间安排所有内容,就像我在最顶层显示的那样(postDataTime表). (我会展示我曾经尝试过的东西,但是我已经搜索了无数个小时的例子来说明我想要完成的事情,但我找不到任何东西,我尝试的东西也不起作用.)
我以为我可以使用exec()函数,但从它看起来不允许我运行函数,否则我会做以下..
$time = '10:30';
if($time == time())
{
exec(myFunction());
}