making code for counting teams from database