Update query.php

almost final code