prepare($sql); $stmt->execute(); $users = $stmt->fetchAll(PDO::FETCH_ASSOC); $total_num = 0; $update_num = 0; $isUps = ''; foreach( $users as $k=>$v ){ $total_num++; $sql = "select * from `order` where user_id={$v['user_id']} limit 1"; $stmt = $_PDO->prepare($sql); $stmt->execute(); $res = $stmt->fetch(PDO::FETCH_ASSOC); if(!empty($res)){ $isUps .= $v['user_id'].','; } } if($isUps != ''){ $isUps = rtrim($isUps, ','); $sql = " update red_user_mission set status=1 where user_id in({$isUps}) "; $stmt = $_PDO->prepare($sql); $stmt->execute(); $update_num = $stmt->rowCount(); } echo "\n总共".$total_num."条数据"; echo "\n成功更新".$update_num."条数据";