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?
P粉448732323
P粉448732323 2022-04-24 12:05:55
0
1
993

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..

P粉448732323
P粉448732323

reply all(1)
autoload

Get the latest 20 data IDs in the database, then use whereNotIn() to filter them out, and then delete them

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!