How to dynamically change multiple global variables in my request and call the same request again while dynamically changing these variables

Hello,

I am trying to change the URL dynamically using global variables. I am trying to change two different global variables in the same request.

My script:

Here I am looping the search by (global variable) and after the loop ends, I want to change the per page (global variable). When I use another if loop it is not giving me the desired output.

P.s I am doing negative testing.

How can I achieve this? It is working if both are in separate requests.