Urlencode query parameters in the same function in which query is done instead of calling script