Php While Loop Sql Query Formatter