php 循環從數據庫分頁取數據批量修改數據


 1  //批量修改email重復
 2     public function getEmail()
 3     {
 4         $this->model = app::get('shop')->model('manage');
 5         //總條數
 6         $count = count($this->model->getList('id', [ 'status' => 1, 'type' => 0]));
 7 
 8         $limit = 0;
 9         $num = $count / 5;//循環多少次
10         for ($i = 1; $i <= $num; $i++) {
11             $sql = "select * from shop_manage where type = 0 AND status = 1 order by id limit {$limit},5";
12             $list = app::get('base')->database()->fetchAll($sql);
13 
14             foreach ($list as $k => $v) {16                     $email = $v['email'];
17
18                     $user_id = $v['user_id'];
19                    
20
21                     $email = $user_id . '_cfq_' . $email;
22 
23                     $result=$this->model->update(['email'=>$email],['user_id'=>$user_id]);
24 
25                 }
26 
27
28 29 $limit += 5; 30 } 31 $message = "處理成功!"; 32 return $this->splash('success', null, $message); 33 34 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM