SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Hi!

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Location
    Aveiro, Portugal
    Posts
    164
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Hi!

    I'm having trouble with querystring parameters.

    I use the querystring parameters to drilldown on a car search.

    1- How do I prevent the parameters from being duplicated:
    I don't want this to happen: http://localhost/page.php?price=1&price=2

    2- How can I do it so the order of the parameters doesn't matter, i.e.,

    I can have:
    http://localhost/page.php?price=1&make=2
    or
    http://localhost/page.php?make=1&price=2

    and it still detects the duplicates.

    Thankx for your help.
    Yours truely
    Mário Ramos

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    http://localhost/page.php?price[]=1&price[]=2&make=1

    The prices will be accessible through the price array, and the order will not matter.
    Saul

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2005
    Location
    Aveiro, Portugal
    Posts
    164
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Hi php_daemon

    Thanks for the reply.

    But what I really wanted was to not have duplicated parameters. Only 1 price, 1 make, etc.
    Yours truely
    Mário Ramos

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Why would you have duplicated parameters?

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2005
    Location
    Aveiro, Portugal
    Posts
    164
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Duplicate Parameters

    That's the problem... I get duplicate parameters. I I don't want them.
    I guess I get the duplicate parameters because I take the existing url and add the new parameter. But sometimes it's an already existing parameter but with a new value.

    I need a way to check if the parameter already exists in the url. If so, modify it's value, not add it to the querystring
    Yours truely
    Mário Ramos

  6. #6
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all i want to suggest you mjpr to give something meaningful thread title. Because you are not here not only say HI!. Only knocking might not help you to open the door.

    I am sorry if i said something nonsense. Lol!

    Does your query string comes from the browser's address bar or you get it from somewhere. You can check with $_SERVER['QUERY_STRING']; if you are getting it form the browser's address bar. Otherwise i think you should check whether the ? (question mark) is already contained with the query string or not.

    Does this guide to some right direction?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  7. #7
    SitePoint Zealot
    Join Date
    Feb 2005
    Location
    Aveiro, Portugal
    Posts
    164
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Rebuild Querystring

    Finally got it.

    I used a function I found on a site (finalwebsites.com)

    function rebuild_qs($curr_vars) {
    if (!empty($_SERVER['QUERY_STRING'])) {
    $parts = explode("&", $_SERVER['QUERY_STRING']);
    $curr_vars = str_replace(" ", "", $curr_vars); // remove whitespace
    $c_vars = explode(",", $curr_vars);
    $newParts = array();
    foreach ($parts as $val) {
    $val_parts = explode("=", $val);
    if (!in_array($val_parts[0], $c_vars)) {
    array_push($newParts, $val);
    }
    }
    if (count($newParts) != 0) {
    $qs = "&".implode("&", $newParts);
    } else {
    return false;
    }
    return $qs; // this is your new created query string
    } else {
    return false;
    }

    works like a charm.

    Thankx for all your input and help.
    Yours truely
    Mário Ramos


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
  •