# Adding a var to a URL with a var

**URL:** <https://forum.kirupa.com/t/adding-a-var-to-a-url-with-a-var/272023>\
**Category:** programming\
**Created:** [October 1, 2008, 11:57am UTC](https://forum.kirupa.com/t/adding-a-var-to-a-url-with-a-var/272023 "2008-10-01T11:57:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![W92Baj](https://avatars.discourse-cdn.com/v4/letter/w/a88e4f/32.png) [@W92Baj](https://forum.kirupa.com/u/W92Baj)\
**Post date:** [October 1, 2008, 11:57am UTC](https://forum.kirupa.com/t/adding-a-var-to-a-url-with-a-var/272023/1 "2008-10-01T11:57:43Z")

</div>

OK this is probably simple but here goes.

I have a parsed URL ( [www.foo.com?bar=1](http://www.foo.com?bar=1)).

It is being used as part of a search function and an SQL query is built from this variable ( SELECT \* from foo WHERE bar=$bar).  
I have a link on that page which will narrow down the results ( SELECT \* from foo WHERE bar=$bar AND cheese=1).  
However if I have the link as \<a href=".$\_SERVER[‘PHP\_SELF’]."&cheese=1\> the PHP\_SELF ignores the bar variable already in the URL.

Is there a way to include it without having if statements on each link to check if $bar exists?
