prepare($sql); $stmt->execute(); $userIds = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach($userIds as $k=>$v){ $sql = " select id from red_user_mission where type=1 and user_id={$v['user_id']} "; $stmt = $_PDO->prepare($sql); $stmt->execute(); $red_mission = $stmt->fetch(PDO::FETCH_ASSOC); $user_id = $v['user_id']; $union_id = $v['union_id']; $is_mission = 0; if(!empty($red_mission)) $is_mission = 1; $sql = "insert into red_nologin_users (user_id, union_id, is_mission) values({$user_id},'{$union_id}',{$is_mission}) "; $stmt = $_PDO->prepare($sql); $stmt->execute(); }