Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post

    how to $_GET multiple values

    Is there an easy way to $_GET multiple values from the url:
    Code:
    ?type=forforum&no=0&source0=tr&btitle0=Matthew&no=1&source1=kjv&btitle1=Matthew&checkresult0=1&checkresult1=23195
    The reason I ask is because I want to add more to this later on such as:
    PHP Code:
    ?type=forforum&no=0&source0=tr&btitle0=Matthew&no=1&source1=kjv&btitle1=Matthew&checkresult0=1&checkresult1=23195&no=2&source2=kjv&btitle2=Matthew&checkresult2=23195&no=3...&no=4... 
    This is how it's interpreted so far:
    PHP Code:
    $bk=isset($_GET["book".$no]) ? $_GET["book".$no] : "";
    $ch=isset($_GET["chapter".$no]) ? $_GET["chapter".$no] : "";
    $vs=isset($_GET["verse".$no]) ? $_GET["verse".$no] : "";
    $source=isset($_GET["source".$no]) ? $_GET["source".$no] : "";
    $sourceAbb=Array("kjv""mt""mtnv""tr");
    $SourceName=Array("King James""Masoretic Text""Masoretic No Vowels""Textus Receptus");
    $SourceTable=Array($dbTable3$dbTable7$dbTable9$dbTable8);
    for(
    $i=0$i<count($SourceTable); $i++){
        if(
    $source==$sourceAbb[$i]){
            
    $sql "SELECT * FROM ".$SourceTable[$i]." WHERE book = '".$bk."' AND chapter= '".$ch."'";
            if(
    $vs != 'all'){
                
    $sql .= " AND verse= '".$vs."'";
            }
            
    $sql .= " ORDER BY id ASC";
            
    //echo $sql;
        
    }

    Compare bible texts (and other tools):
    TheWheelofGod

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    first problem:, $_GET and $_POST can't contain same value twice, for example:
    using url?no=1&.....&no=6 you can have both 1 and 6 in $_GET['no'], only one of them, probably 6 because is the last one.

    second problem: $_GET lenght is limited use $_POST insted, is limited too but it's limit is bigger.

    you know what parameters you expect so you can build a array:
    PHP Code:
    $expected = array('type' => '',
                                 
    'no' => '',
                                 
    'source0' => '',
                                 
    'btitle0' => '',
                                 
    'source1' => '',
                                 
    'btitle1' => '',
                                 
    'checkresult0' => '',
                                 
    'checkresult1' => '',
                                 
    'source2' => '',
                                 
    'btitle2' => '',
                                 
    'checkresult2' => ''
                              
    );

    foreach(
    $expected as $name => $value){
       if(isset(
    $_GET[$name]) && $value !== ''){
          
    // check if $_GET[$name] is what you expect here
          
    $expected[$name] = $_GET[$name];
       }
    }

    // use $expected[$name] instead of $_GET[$name] 
    best regards
    Last edited by oesxyl; 04-21-2011 at 08:22 PM.

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by oesxyl View Post
    first problem:, $_GET and $_POST can't contain same value twice, for example:
    using url?no=1&.....&no=6 you can have both 1 and 6 in $_GET['no'], only one of them, probably 6 because is the last one.

    second problem: $_GET lenght is limited use $_POST insted, is limited too but it's limit is bigger.

    you know what parameters you expect so you can build a array:
    PHP Code:
    $expected = array('type' => '',
                                 
    'no' => '',
                                 
    'source0' => '',
                                 
    'btitle0' => '',
                                 
    'source1' => '',
                                 
    'btitle1' => '',
                                 
    'checkresult0' => '',
                                 
    'checkresult1' => '',
                                 
    'source2' => '',
                                 
    'btitle2' => '',
                                 
    'checkresult2' => ''
                              
    );

    foreach(
    $expected as $name => $value){
       if(isset(
    $_GET[$name]) && $value !== ''){
          
    // check if $_GET[$name] is what you expect here
          
    $expected[$name] = $_GET[$name];
       }
    }

    // use $expected[$name] instead of $_GET[$name] 
    best regards
    Ok the meaning of the $no is the number. Let's say I'm doing 3 searches then the url should show &no=0...&no=1...&no=2... Unless there's a better way of expressing this. Maybe &no=0+1+2. Or is it necessary to put this at all?
    I want to be able to retrieve all the values which are numbered 0, 1, 2.
    Something like this?
    PHP Code:
     'source'[$no] => '',
                                 
    'btitle'[$no] => ''
    Last edited by gilgalbiblewhee; 04-21-2011 at 08:34 PM.
    Compare bible texts (and other tools):
    TheWheelofGod

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by gilgalbiblewhee View Post
    Ok the meaning of the $no is the number. Let's say I'm doing 3 searches then the url should show &no=0...&no=1...&no=2... Unless there's a better way of expressing this. Maybe &no=0+1+2. Or is it necessary to put this at all?
    I want to be able to retrieve all the values which are numbered 0, 1, 2
    why can't you use no=3 instead and interpret this like the number of search? i mean having no=6 mean 6 searches 0, 1, 2,...,5.

    best regards

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by oesxyl View Post
    why can't you use no=3 instead and interpret this like the number of search? i mean having no=6 mean 6 searches 0, 1, 2,...,5.

    best regards
    Yes but then I'm wondering how I'm going to build the url in the previous .php file. So far I have 2 searches:
    http://gbgrafix.com/thewheelofgod/twotexts/

    and clicking on the What To Do's For Forum Use it has to be accordingly.

    Let's say if I use one search then only 1 should appear in the For Forum Use's url &no=0 or 1?
    Compare bible texts (and other tools):
    TheWheelofGod

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by gilgalbiblewhee View Post
    Yes but then I'm wondering how I'm going to build the url in the previous .php file. So far I have 2 searches:
    http://gbgrafix.com/thewheelofgod/twotexts/

    and clicking on the What To Do's For Forum Use it has to be accordingly.

    Let's say if I use one search then only 1 should appear in the For Forum Use's url &no=0 or 1?
    i'm sorry but i don't understand.
    If you build a search and use a select in the, with single or multiple selections, you probably need a form:

    Code:
    <form method="post" action="someurl">
    <div>
       <p>What To Do</p>
       <select name="mimi" id="mimi" multiple="multiple">
         <option value="0">For Forum Use</option>
         <option value="1">blah blah</option>
         <option value="2">geh, geh</option>
       </select>
    </div>
    </form>
    the submit will take care of sending one or more values.

    http://www.onlinetools.org/tricks/us...ple_select.php

    best regards


  •  

    Posting Permissions

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