我希望每小时都能将最新的项目添加到我的表格中。该表格是从其他来源填充的,我需要跟踪我收到的最后一个ID是什么,并从那时起添加所有新项目。
$check5 = "select * from media_ids";
$rs5 = mysqli_query($con,$check5);
if(mysqli_num_rows($rs5)==1)
{
$row = mysqli_fetch_assoc($rs5);
$media_id=$row['media_id'];
}
// execute query
答案 0 :(得分:4)
crontab -e
然后添加0 * * * * php /path/to/script/script.php
created
的表格中添加一列,将类型设置为TIMESTAMP
,将默认值设置为CURRENT_TIMESTAMP
3A。 - 在最后一小时内获取所有内容 script.php应如下所示:
<?php
$current = time() - 3600;
$currentMediaQuery = "select media_id from media_ids where created > {$current}"
$mediaQuery = mysqli_query($con, $currentMediaQuery);
if (mysqli_num_rows($mediaQuery) > 0) {
while ($row = mysqli_fetch_row($mediaQuery)) {
... do stuff
}
}
3B。获取10,按指令维护指针
<?php
$lastPointer = “select pointer from pointer_tracking”;
$lastPointerResult = mysqli_query($con, $lastPointer);
$lastPointer = mysqli_fetch_row($lastPointerResult)
$lastPointer = $lastPointer[0];
$currentMediaQuery = “select * from media_ids where id > {$lastPointer} limit {$lastPointer}, {$lastPointer +10}”;
$mediaQuery = mysqli_query($con, $currentMediaQuery);
if (mysqli_num_rows($mediaQuery) > 0) {
while ($row = mysqli_fetch_row($mediaQuery)) {
do stuff…
}
}
if (($lastPointer + 10 > 40) {
$lastPointer = 1;
} else {
$lastPointer += 10;
}
mysqli_query($con, “update pointer_tracking set pointer = {$lastPointer}”);
你需要创建一个名为pointer_tracker的表,它有一个id和pointer列,两个整数类型