How to append a search query
4 posts by 2 authors in: Forums > CMS Builder
Last Post: March 23, 2010 (RSS)
By Perchpole - March 19, 2010
Ok, All -
Here's another intersting one that might come in handy...
How do I append a search query?
Let's say I have a URL like this...
www.wibble.com/index.php?range=cars
I want to create a new link on the page which takes the current URL and extends it by adding...
The result is a link which reads...
www.wibble.com/index.php?range=cars&colour=blue
I apreciate that I could just create a new search from scratch - ?range=cars&colour=blue - but in this instance I want to see if I can selectively add elements to the URL as I get deeper into the search.
Do-able?
:0)
Perchpole
Here's another intersting one that might come in handy...
How do I append a search query?
Let's say I have a URL like this...
www.wibble.com/index.php?range=cars
I want to create a new link on the page which takes the current URL and extends it by adding...
&colour=blue
The result is a link which reads...
www.wibble.com/index.php?range=cars&colour=blue
I apreciate that I could just create a new search from scratch - ?range=cars&colour=blue - but in this instance I want to see if I can selectively add elements to the URL as I get deeper into the search.
Do-able?
:0)
Perchpole
Re: [Perchpole] How to append a search query
By Chris - March 22, 2010
Hi Perchpole,
You can use @$_SERVER["QUERY_STRING"] to get the search query for the current page. Use it like this:
Does that help? Please let me know if you have any questions.
You can use @$_SERVER["QUERY_STRING"] to get the search query for the current page. Use it like this:
<a href="?<?php echo @$_SERVER["QUERY_STRING"] ?>&colour=blue">
Does that help? Please let me know if you have any questions.
All the best,
Chris
Chris
Re: [chris] How to append a search query
By Perchpole - March 22, 2010
Hi, Chris -
Thanks - as ever - for your input. It's much appreciated.
However, last night, I had a bit of a dig around and came up with this...
This pulls the URL from the page whereas yours gets the search query - which (I think) means the link by which the visitor arrived on the page.
Are there practical reasons why I should use one in preference to the other?
:0)
Perch
Thanks - as ever - for your input. It's much appreciated.
However, last night, I had a bit of a dig around and came up with this...
"http" . ((!empty($_SERVER['HTTPS'])&&$_SERVER['SERVER_PORT']!=443) ? "s" : "") . "://". "www.". $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
This pulls the URL from the page whereas yours gets the search query - which (I think) means the link by which the visitor arrived on the page.
Are there practical reasons why I should use one in preference to the other?
:0)
Perch
Re: [Perchpole] How to append a search query
By Chris - March 23, 2010
Hi Perchpole,
If you need to construct an absolute URL, your code is the way to do it. If all you need is a relative URL, what I posted above is a little simpler.
If both of these links where found on the page http://example.com/hello/world.php?range=cars, they would both result in the browser going to the same address:
I hope this helps. Please let me know if you have any questions.
If you need to construct an absolute URL, your code is the way to do it. If all you need is a relative URL, what I posted above is a little simpler.
If both of these links where found on the page http://example.com/hello/world.php?range=cars, they would both result in the browser going to the same address:
<a href="?range=cars&colour=blue">relative</a>
<a href="http://example.com/hello/world.php?range=cars&colour=blue">absolute</a>
I hope this helps. Please let me know if you have any questions.
All the best,
Chris
Chris