Php While Loop Sql Query Compiler Design Questions