need solution for $_GET page..

Discussion in 'PHP' started by khan11, Sep 16, 2007.

  1. #1
    Hi guys!


    I have most of my pages created using arrays & variables but i am displaying all of them in this form >> mypage.php?getdata=0&todata=10

    it works fine but, when we open mypage.php , the data doesn't come because we have nothing in it.. what i want is, when people try to enter mypage.php in address bar, they are automatically moved to mypage.php?getdata=0....

    i tried header, include but didnt work..

    any other solution or ideas will surely be appreciated. ..
     
    khan11, Sep 16, 2007 IP
  2. Noodles25

    Noodles25 Active Member

    Messages:
    75
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #2
    Try something like this:

    
    function getRequestParameter($name, $default=null) {
      return array_key_exists($name, $_REQUEST) ? $_REQUEST[$name] : $default;
    }
    
    PHP:
    Then when you're referencing your query string variable do this:
    
    $getdata = getRequestParameter("getdata", 0);
    
    PHP:
    That way if it doesn't exist it will get assigned the default value. I use this all the time in my scripts.
     
    Noodles25, Sep 16, 2007 IP
  3. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    sorry, not working for me :(

    or do i need to change the values? when i try to change its values it gives some error.

    you edit this code to meet my page requirements.

    For example:

    my page is: mypage.php
    i want to redirect to: mypage.php?getdata=0&todata=10

    thnx
     
    khan11, Sep 16, 2007 IP
  4. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if (!$_GET)
    	header("Location: ?getdata=0&todata=10")
    PHP:
     
    MMJ, Sep 17, 2007 IP
    khan11 likes this.
  5. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Worked!

    Thank you so much...

    I was not expecting any more suggestions but you did it..

    + for u...
     
    khan11, Sep 17, 2007 IP
  6. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Glad to help. :)

    Thanks for the Rep. :)
     
    MMJ, Sep 17, 2007 IP