Using functions with database queries and table displays