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 }

 

posted @ 2018-12-21 16:02  Mr、桔子  阅读(1103)  评论(0编辑  收藏  举报