if($logNums >= 20) {
$logList = $tableLog->limit(20)->order("id", "asc")->select() ;
foreach($logList as $k => $v){
$condition[] = $v['id'];
}
$tableLog->where('id', 'in', $logList)->limit(20)->order("id", "asc")->delete();
}
I would like to ask someone about the problem of thinkphp operating database. How to keep the latest 20 entries and clear the redundant ones if they are larger than 20?
Thanks in advance for the answer..
autoload2022-04-25 09:58:52
Get the latest 20 data IDs in the database, then use whereNotIn() to filter them out, and then delete them