download in loop and puts query