Results 1 to 6 of 6

Thread: Adding To Url Parameters

  1. #1
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Adding To Url Parameters

    Hi Everyone,

    I am back with a new problem I am stuck on.

    I am trying to add to a url's paramters but cant get anything working.

    if I have url: http://www.test.com/Search?Cat=1

    and i would like to add on to the url when someone clicks on the link how would I?

    For example I want it to now be: http://www.test.com/Search?Cat=1&User=1

    Any help would be helpful.

    Thanks.

    Sukh

  2. #2
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    I'm not super clear about what you are trying to do. If this doesn't answer your question, let me know.

    You will first have to somehow get a value for the User variable. Once you have that you can make your link like this:

    PHP Code:
    <?php

    $user 
    1;

    ?>

    <a href="http://www.test.com/Search?Cat=1&User=<?php echo $user?>">Search</a>

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    You can do this through JS rather than using PHP as the click is going to happen on the browser. Try the following code

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    		<title>Untitled Document</title>
    	</head>
    	<body>
    		<p><a href="http://www.test.com/Search?Cat=1" id="one">Click to add Parameters</a></p>
    		<script type="text/javascript">
    			document.getElementById("one").onclick = function(){
    				this.href += "&User=1";
    				alert(this.href); //Just to get a notification you can remove this.
    			}
    		</script>
    	</body>
    </html>

  4. #4
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks codeexploiter, i will give that a try.

    Well JasonDFR, what I am trying to is take the current url, in the path for example: http://www.test.com/?ID=1&User=1

    and when someone clicks on the link, that I need a $_GET for, i would like to add it on the url with ease and not lot of extra statements.

    So if someone clicked the link, and I want the page reloaded I just want to add on extra details to the url path so now I want it to look like
    example: http://www.test.com/?ID=1&User=1&Search=2

    I need to solve this issue because I am working on the searching of my website, but I also have a place where you can change the currency, if someone searches something, then tries to change the currency they don't get and error, the search page will reloaded but the search is lost.

    I would like to still keep the research data in the url and add the currency change variables as well to the url path.

  5. #5
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    codeexploiter, its helpful what you provided me with, but what if in the situtation is there no ? in the url path it would throw and error.

    I need it to check to see if there is a ?ID=Something then just add &Currency=CDN, if there is not ?ID=Something then I need it to add ?Currency=CDN.

    Any suggestion to that ?

  6. #6
    Join Date
    Mar 2009
    Posts
    65
    Thanks
    13
    Thanked 4 Times in 4 Posts

    Default

    use strpos() to find if the current url has a question mark
    If there is, the path is likely to be valid.

    OTH, there is a http_build_query() command which you may want to look into.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •