What I am trying to do with $ncount is reset it to 0 each time in the loop. Then I want to do a query on my database to see if the record is there. The result number should be assigned to the $ncount and if the count is gt 0 then do something else something else.