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

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

<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