Multiple GETs in a URL at the same time?

I am trying to get variables from a url, but every time the url already has a request, it is overwritten with the following request. Example: I have a link:

<a href="?page=34">Page 34</a> 

When you click on this link, this link becomes visible;

 <a href="?item=45">Item 45</a> 

But when I click this link, the other one is rewritten, so the URL looks like this:

www.domainname.ext /? Item45

But I want it to look like this:

?

www.domainname.ext / page = 34 & item45

How to do it? Thanks in advance!

+6
html php
source share
4 answers

Within the specified "page" you need to save the page identifier and use this saved value when creating the "item" links.

 <?php $pageID = $_GET['page']; // .... ?> <a href="?page=<?php echo $pageID; ?>&amp;item=45" title="Item 45">Item 45</a> 
+5
source share

You can also use http_build_query(); to add additional parameters to your URL

 $params = $_GET; $params["item"] = 45; $new_query_string = http_build_query($params); 

PHP http_build_query

eg:

 $data = array('page'=> 34, 'item' => 45); echo http_build_query($data); //page=34&item=45 

or turn on amp

 echo http_build_query($data, '', '&amp;'); //page=34&amp;&item=45 
+5
source share
 <a href="?page={$page->id}&amp;item={$item->id}"> Page {$page->id}, Item {$item->id} </a> 
+3
source share

When displaying links, you will need to include all the relevant query string parameters; there is no automatic "merge".

If you can change your server stuff to use RESTful URLs , you can get this behavior. For example, starting with

 http://www.domainname.ext 

this link

 <a href='page34'>Page 34</a> 

will lead you to

 http://www.domainname.ext/page34 

after which this link

 <a href='item43'>Item 43</a> 

will lead you to

 http://www.domainname.ext/page34/item43 

... but this requires significant changes in your server materials.

+2
source share

All Articles