Reputation: 3570
I have a sub-navigation menu on my page that opens up whenever ?n=review
is appended to the URL.
I also have languages changing and session variables being set whenever ?language=xx
is appended.
However, if I am on a page with the sub-nav open, and I wish to change language from there, the ?n=review
is replaced with ?language=xx
upon link click, and therfore the sub-nav closes. How would I check to see if a $_GET
variable is already set every time the language is changed, and if so, append my additional one to the end?
Once the language has been changed, the new language is set to a session variable so I do not need to worry about keeping it's $_GET
variable. I'm wondering if I would need to store the sub-nav variable in the same way...?
Sorry if this question is worded badly, I'm trying to get my head around the logic myself.
If you need to see any code or tidier wording, please let me know before down-voting.
Upvotes: 0
Views: 133
Reputation: 3917
if(empty($_GET['language'])) {
$fragment = '?n=review';
} else {
// if language is set, get the value
$lang = $_GET['language'];
$fragment = "?language=$lang&n=review";
}
// I just made up the /index.php part, replace that with the proper link.
$url = "/index.php$fragment";
Upvotes: 1
Reputation: 2436
Get variables can be chained by using the '&' Character. So you could build your link that way:
echo "./?n=review&language=xx"
If you want to know, if any $_GET parameters have been set, you can simply use PHP's empty()
function like this:
if( empty( $_GET ) )
{
//$_GET is empty
}
else
{
//$_GET has something in it
}
Upvotes: 0