I'm trying to GET variables out of an URL, but everytime the URL already has a query, it gets overwritten by the next query. Example: I have a link;
<a href="?page=34">Page 34</a>
When you click on that link this link becomes visible;
<a href="?item=45">Item 45</a>
But when I click that link, the other one get overwritten so the URL looks like;
www.domainname.ext/?item45
But I want it to look like;
www.domainname.ext/?page=34&item45
Any way to do that? Thanks in advance!
From within a given "page", you need to store the page ID and use that stored value when you create "item" links.
<?php
$pageID = $_GET['page'];
// ....
?>
<a href="?page=<?php echo $pageID; ?>&item=45" title="Item 45">Item 45</a>
You can also youse http_build_query();
to append more params to your URL
$params = $_GET;
$params["item"] = 45;
$new_query_string = http_build_query($params);
PHP http_build_query
for instance:
$data = array('page'=> 34,
'item' => 45);
echo http_build_query($data); //page=34&item=45
or include amp
echo http_build_query($data, '', '&'); //page=34&&item=45
<a href="?page={$page->id}&item={$item->id}">
Page {$page->id}, Item {$item->id}
</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With