Php While Loop Sql Query Compiler Python 3