What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    How should I parse the PHP given in a matrix?

    Asked by jalleyne on June 22, 2015 at 12:33 PM

    I'm trying to parse the data in a matrix form question to an individual entry in a mySQL database. Though I understand how to parse strings in PHP, the output for that question (using the method from this link: http://www.jotform.com/help/51-How-to-Post-Submission-Data-to-Thank-You-Page) Comes out as an array with one entry:

    I need to parse each entry within the array as an entry into a database. (ie explode() the elements in Array and attach them to variables in the database, eventually getting to the point so that a $chain variable would hold a value "delta / gamma" string. 

    It seems as if the " " either aren't registering on the text editor I'm using or the "" are one character off. Can you suggest a way of solving the problem?

    Page URL:
    http://www.irepertoire.com/#!sample-submission-form/ctc0

    in how JotForm problem POST uploads
  • Profile Image
    JotForm Support

    Answered by KadeJM on June 22, 2015 at 02:54 PM

    To my understanding I believe you mean you wish to separate your arrays at the moment.

    Are you trying to just separate the arrays into individual lines each? 

    Or were you intending to split those up and have those then become attached with the variables that are already associated to be pulled into your database?

    Please allow us some time to look into this and if we're able to do so then we'll update you here.

     

  • Profile Image

    Answered by jalleyne on June 22, 2015 at 03:07 PM

    My intention is to take the long string within the arrays and allocate them to variables defined in the database. So the really rough process would look something like:

    given: 

    [sampleinformation] =>

       Array ([0] => ["long string of things"] [1] => ["long string of things"]....)

     

    loop through each entry of the array 'sampleinformation'.

    For each index in the array, parse the long string held at that index. 

    allocate each token of the string (ie the tokens " ", "024 JRG" , "7.7" in the original example) to a variable in a mySQL database. So that a table 'sample' in the database refers to an element in the 'sampleinformation' array and the rows of that mySQL table refer to the tokens parsed from the array. 

     

  • Profile Image
    JotForm Support

    Answered by BJoanna on June 22, 2015 at 05:15 PM

    Did you try some code for example you provided? To iterate through array you can use foreach function. Foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. There are two syntaxes:

    foreach (array_expression as $value)

        statement

    foreach (array_expression as $key => $value)

        statement

     

    There is an interesting article on stackoverflow how to iterate over array and split elements inside of array with delimiters. 

    http://stackoverflow.com/questions/16476140/php-array-explode-some-comma-separated-elements-into-new-items 

    You can modify this example in order to adjust it to work for you:

    $format_Arr = array("test1","test2,test2.1","test3","test4,test5,test6,test7");

    $formated_arr = array();

    foreach($format_Arr as $arr){

    $arr1 = explode(",",$arr);

    if(count($arr1)>1){

        $formated_arr = array_merge($formated_arr,explode(',',$arr));

    }else{

        $formated_arr[]= $arr;

    }

    }

    print_r($formated_arr);

    Hope this help. Let us know if you need further assistance.