Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple GETs in URL at the same time?

Tags:

html

php

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!

like image 431
Jay Wit Avatar asked Feb 28 '11 15:02

Jay Wit


3 Answers

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; ?>&amp;item=45" title="Item 45">Item 45</a>
like image 131
Orbling Avatar answered Oct 17 '22 19:10

Orbling


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, '', '&amp;');  //page=34&amp;&item=45
like image 35
KJYe.Name Avatar answered Oct 17 '22 19:10

KJYe.Name


<a href="?page={$page->id}&amp;item={$item->id}">
    Page {$page->id}, Item {$item->id}
</a>
like image 3
Halil Özgür Avatar answered Oct 17 '22 21:10

Halil Özgür