use query not array loop