cycero
cycero

Reputation: 4771

Preserve $_GET variables in query string after page reload PHP

In my PHP application I have several options for sort, say, clicking on one link will put ?vendor=1 into the query string and it will affect the data coming from the database, and I have another link which sets another value as a sort condition. In normal it will look like the following:

http://somesite.com/index.php?vendor=1&site=2

However, when the query string has only one variable, say ?vendor=1 and I click on the second link to set the second sort variable, the query string is being reset and I get only the second variable in the query string. One of those variable setters is a select and the other is a link.

Could anybody help me with this, please?

Thanks.

Upvotes: 1

Views: 1273

Answers (3)

Jacob
Jacob

Reputation: 66

You can store the criterias in a session variable, that in contrast to the request parameters are preserved between requests.

In PHP, the session variable is accessed through the $_SESSION array variable.

Upvotes: 2

Quentin
Quentin

Reputation: 943999

You cannot construct a relative URI in such a way as to change an existing query string.

You will need to dynamically generate your links to preserve any query string data you want.

Upvotes: 0

user827080
user827080

Reputation:

In your form that encapsules the select tag, try putting the form action to the current page, including (if any) the get queries. Then also make the link point to the same URL. I think that should fix it.

Upvotes: 0

Related Questions