6 Replies Latest reply on Mar 3, 2009 12:59 PM by Dan Bracuk

    working with Lists

    jbird5k Level 1
      i have bee asked to take a form response and out put it to a table. the response field of the db is populated like so::
      "Kelly Wadell | Transferred from POU | 2/1/2009
      John Dolce | Transferred from HQ |10/1/2008
      David Fargnoli | Transferred from POU | 1/6/2008
      after each date is a return when I code my listgetat to capture the return tempVar=listgetat(response, 1,'|')tempVar2=listgetat(response, 2,'|')

      the above should produce a table with 3 rows of data

        • 1. Re: working with Lists
          -==cfSearching==- Level 4
          So what is your question ? (ie Which part are you having difficulty with)
          • 2. Re: working with Lists
            jbird5k Level 1
            My problem is the "return" after each set of data. I can only get the first 2 pieces of data in this case Kelly Wadell and Transferred from POU .

            my tempVar3, which should be the date is either empty if I set the delimeter to try and find the "return" ( used &ch13; and \n ) or I get the date and the name of the next person.

            How do i get the 3 pieces of information into something that can be output to a table with each piece in its own column?

            Thanks, the first post the mind was moving faster than the hands.

            • 3. Re: working with Lists
              -==cfSearching==- Level 4
              Treat the value as nested lists. Loop through it using return ( chr(13) and/or chr(10) as the row delimiter. That will split the data into rows. Then split each row into columns using "|" as the delimiter.

              If you are using CF8, I would recommend using arrays instead of list functions. The listToArray(..) function now supports empty elements. So your script will not break if one of the values is omitted.

              <cfloop list="#response#" index="row" delimiters="...">
              <cfset cols = listToArray(row, "|", true)>
              ... do something with the values here ...

              • 4. Re: working with Lists
                jbird5k Level 1
                I got it.

                [code]<cfloop query="getQ599Response">
                <cfif (getQ599Response.question_id EQ 911 OR question_id EQ 1282 ) and isDefined('response')>
                <CFSET rep = #response#>

                <cfloop list="#rep#" index="i" delimiters="#chr(13)#">
                <cfloop list="#i#" index="j" delimiters="|"><td>#j#</td></cfloop>
                • 5. working with Lists
                  -==cfSearching==- Level 4
                  Good. Keep in mind your script may break/display incorrectly if there are empty values. List functions do not handle empty elements well.

                  > <CFSET rep = #response#>

                  BTW, the separate variable is not needed. Just use the #response# variable.
                  • 6. Re: working with Lists
                    Dan Bracuk Level 5
                    If you have the opportunity, you should alter that table so that each list element of the response is in it's own field.