How to append a search query

4 posts by 2 authors in: Forums > CMS Builder
Last Post: March 23, 2010   (RSS)

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:

<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

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...

"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:

<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