A much better way to do it is using SQL. Are you familiar with that?