ExecuteS(' SELECT r.`id_order_return` FROM '._DB_PREFIX_.'order_return r WHERE r.state = 2 AND r.date_upd < DATE_SUB(NOW(), INTERVAL 3 MONTH)' ); $id_to_update = array(); foreach ($order_returns as $return) { $id_to_update[] = (int)$return['id_order_return']; Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'order_return_history VALUES (DEFAULT,1,'.(int)$return['id_order_return'].',6,NOW())'); } Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'order_return SET state = 6 WHERE id_order_return IN ('.implode(',', $id_to_update).')'); exit;