SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: The Querystring

  1. #1
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello there, I've got two little questions regarding the querystring in PHP.

    First one:
    Is it possible to pass a variable in an included file ?, like this:
    PHP Code:
    include ("data.php?value=1"); 
    Second one:
    I've finally managed to get a PHP search script together with a conversion of a MSAccess DB to MySQL (yay me, three days before I didn't have a clue about these), and I would like the querystring to be the clearer possible.
    The page is here: http://www.adecec.net/infcor (you won't be able to search since it doesn't have all the words yet, and it's in french/corsican)
    The problem is, the querystring passes values of all fields, even those haven't been filled.
    So how do I make the querystring ignore fields that haven't been filled ?

    Thanks for your time
    [blogger: zengun] [blogware contributor: wordpress]

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't have time to check out the second question but the first question, you can just establish the var before calling include

    PHP Code:
    $value 1;
    include (
    "data.php"); 
    All include does is bring the contents of the file into the current file.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Second question: yes there is a way of doing it but it's a bit of a round-about solution. Basically the query string thing is nothing to do with PHP - that's how browsers work when you submit a form and some fields are left blank.

    If it's really bugging you you can POST the form contents to a very simple PHP script qhich simply then builds a query sting with only the values that were filled in and then redirects the browser to that new location.

    Here's the script - this will work with ANY form you care to mention
    PHP Code:
    $url 'script.php?'// Variable to store the query string as it is built - 
    // set it to the name of the script that should be executed.

    while(list($key$val) = each($HTTP_GET_VARS)) {
        if (
    $val) {
            
    $url .= "$key=$val&";
        }
    }

    header("Location: $url"); 
    That code uses a location header so there can't be anything sent to the browser before it is executed. Note that I couldn't be bothered to stick in the logic for only adding an '&' sign if there are more terms to be stuck on the query string - you can add that if you want to.

    Code is untested...

    Hope it helps
    Last edited by Skunk; May 7, 2001 at 14:40.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why not use method POST for your form?

  5. #5
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not POST ? Because I want the results to be URLs, that can be bookmarked or accessed from any page. (eg. : Merriam-webster dictionnary, Google...)

    Thanks for your suggestions guys
    Skunk I'll test your script, that was a thing I thought about originally but I thought there'd be a direct way so I was abandoning the idea.
    [blogger: zengun] [blogware contributor: wordpress]


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
  •