analytical queries, php script