Since you are storing it in a database just query for only those records that match your criteria using SQL. The alternative is to log every hit and include hostname. Then when reporting group by hostname. That way you can gather statistics like unique hits on a daily basis (coming back the next day counts agian), or total hits per month, etc. Databases are powerfull so use that power when trying to find records. You should seldom if ever need to loop threw records to find matchs.