$m = M(‘service_loginlog‘); $res =$m->where(‘card_id=‘.$_SESSION[‘card_id‘])->order(‘time desc‘)->select(); foreach($res as $k=>$v){ if($k>20){ $m->where(‘id=‘.$v[‘id‘])->delete(); } }
用foreach循环,当$k>20的是后,就执行删除命令
yourphp超出20记录自动删除,布布扣,bubuko.com
原文:http://www.cnblogs.com/wesky/p/3907845.html