在这行代码中,它仅选择前 20 个,但我希望第一次选择前 20 个,然后选择其他等等:'( 我该如何解决这个问题?
function something_cron()
$query = db_select('watchdog', 'wa')
->extend('PagerDefault')
->orderBy('wid')
->fields('wa', array('variables', 'type', 'severity',
'message', 'wid', 'timestamp'))
->limit(20);
$result = $query->execute();
// Loop through each item and add to $row.
foreach ($result as $row) {
someother();
}
我也想避免这个 PagerDefault 但我不能..
最佳答案
首先,如果您不显示寻呼机,则不需要 PagerDefault。您可以使用orderBy和 range没有它。
如果我理解你的帖子,每次运行 cron 时,你都需要看门狗表的前 20 行。如果是这种情况,我建议跟踪从表中获得的最后一个看门狗 ID (wid),并将其用于后续的每次运行。像这样的东西:
$wid = variable_get('my_last_wid', 0);
$result = db_select('watchdog')
->fields('watchdog', array('variables', 'type', 'severity', 'message', 'wid', 'timestamp'))
->condition('wid', $wid, '>')
->orderBy('wid')
->range(0, 20)
->execute();
foreach ($result as $watchdog) {
// do whatever you need to do
}
if (!empty($watchdog)) {
variable_set('my_last_wid', $watchdog->wid);
}
关于php - 使用 limit(20) 时,它仅运行 DB 的前 20 个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29102860/