Multiple Query Strings

danielneridanielneri WP V.I.P.VPS - Virtual Prince of the Server
ex. index.php?id=24&c=1

php code?
ban1.gif

Comments

  • ChroderChroder Senior Member The Royal RAM
    What do you want =/

    $_GET and $_GET will hold the values...
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    well i use it as
    [PHP]
    if($QUERY_STRING == "") {
    // Main Page
    }
    elseif($QUERY_STRING == "foo"){
    // the foo page
    }
    [/PHP]

    which gets it like this

    [PHP]http://www.vipercreations.com/login.php?login[/PHP]

    instead of using login.php?id=1

    i want to know how to use a multiple query string ex. login.php?login&referralid=1 just for an example or even
    login.php?test&test2

    any ideas?
    ban1.gif
  • PythonPython Forum Leader The Royal RAM
    I dont really know what you mean. Well I understand that you want to use two variables in a url but thats only done in certain situations.... Heres an example. Ive used the the switch feature in PHP...

    This script is to be passed using script.php?page=1&number=4

    [PHP]<?php
    $page = $_REQUEST[page];
    $number = $_REQUEST[number];
    switch($page)
    {
    case 1:
    echo "This is page ".$page."<br/>";
    if($number < 5)
    {
    echo $number." is less than 5";
    }
    break;

    case 2:
    echo "This is page ".$page."<br/>";
    if($number < 10)
    {
    echo $number." is less than 10";
    }
    break;

    default:
    echo "Page has not been set";
    }
    ?>[/PHP]

    Try that... Put it into a file called script.php and then call it as script.php?page=1&number=4

    The Royal Ram

  • ChroderChroder Senior Member The Royal RAM
    First, create an array of the possible actions you want to take. Then loops through the array, testing each value to see if the index exists in the $_REQUEST superglobal.

    [php]//
    // Possible actions
    //
    $actions = array( 'main',
    'login',
    'foobar'
    );

    $do = 'main'; // Default


    //
    // Test which action to take
    //
    foreach($actions as $act)
    {
    if(isset($_REQUEST[$act]))
    {
    $do = $act;
    break;
    }
    }


    //
    // Do the correct action
    //
    switch($do)
    {
    case 'main':
    // Main
    break;

    case 'login':
    // Login
    break;

    case 'foobar':
    // Foobar
    break;
    }[/php]

    This'll let you do things like script.php?main, script.php?login, script.php?foobar etc.

    The reason this works is because you are still creating a variable in the query string even hough you are not assigning it a value. When you say script.php?main=1, you are assigning 1 to main. If you say just script.php?main, you still have the main variable but it's just empty (and remember, empty != unset). All we have to do is perform the simple test of existance and we can identify which was passed to us.

    Then to use any other values, you can just use $_GET like usual. script.php?login&name=myname, you can still use $_GET etc.
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    thanks guys, but im fine now

    [PHP]
    if($QUERY_STRING == ""){
    //default
    }
    elseif($QUERY_STRING == "login"){
    login
    }
    [/PHP]

    same thing as your switch example chroder, but more suitable to my cause, but u cleared it up thanks
    ban1.gif
Sign In or Register to comment.