Results 1 to 1 of 1

Thread: Normal or arrayed query string.

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Normal or arrayed query string.

    So I have the following function that's grabbing some data from the query string:
    PHP Code:
    function getQueryData($dataToGet$queryIndex=-1)
    {
    // WARNING: This needs to have inputs sanitized. Do not have this accessible from the internet until this is done! Look at the "filter_input" funtion in PHP's documentation.
      
    if ($queryIndex > -1) {
        if (isset(
    $_REQUEST[$dataToGet][$queryIndex])) {
          
    $outputString=$_REQUEST[$dataToGet][$queryIndex];
        } else {
          if (
    $_REQUEST[$dataToGet]!="") {
            
    $outputString=$_REQUEST[$dataToGet];
          } else {  
            
    $outputString="";
          }
        }
      } else {
        
    $outputString=$_REQUEST[$dataToGet];
      }

      return 
    $outputString;


    Here's what it should do:
    When calling this function I'm using this way for loops (If the query string supplied is in an array):
    PHP Code:
    $someData=((getQueryData("somedata"$i) >= || getQueryData("somedata"$i) !="") ? getQueryData("somedata"$i) : 123); 
    And this way for non-arrayed query string parameter (Should also grab the first index in the array when no index is specified and the query string parameter is an array):
    PHP Code:
    $someData=((getQueryData("somedata") >= || getQueryData("somedata") !="") ? getQueryData("somedata") : 123); 
    Here's an example way of running this from the query string:
    &somedata[]=111&somedata[]=222&somedata[]=333
    Which would make somedata[0]=111, somedata[1]=222, somedata[2]=333
    or
    &somedata=456&somedata[3]=111
    Which would make the getQueryData function return 456 in all cases, except when index 3 is called.

    Here's my problem:
    This line:
    PHP Code:
    $outputString=$_REQUEST[$dataToGet][$queryIndex]; 
    Doesn't differentiate between proper arrays and splitting up integers/strings. So for example:
    somedata[0]=111, somedata[1]=222, somedata[2]=333
    getQueryData("somedata", 1); will just return 2, not 222.
    I don't want it to split the string/integer up into an array.

    Does anyone have a suggestion on how to achieve this?
    Last edited by Slyke; Mar 6th, 2014 at 09:43 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width