Skip to main content
jbird5k
Inspiring
March 3, 2009
Answered

working with Lists

  • March 3, 2009
  • 5 replies
  • 596 views
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

tia
J
This topic has been closed for replies.
Correct answer jbird5k
I got it.

<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)#">
<tr>
<cfloop list="#i#" index="j" delimiters="|"><td>#j#</td></cfloop>
</tr>
</cfloop>
</cfif>
</cfloop>

5 replies

Inspiring
March 3, 2009
If you have the opportunity, you should alter that table so that each list element of the response is in it's own field.
Inspiring
March 3, 2009
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.
jbird5k
jbird5kAuthorCorrect answer
Inspiring
March 3, 2009
I got it.

<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)#">
<tr>
<cfloop list="#i#" index="j" delimiters="|"><td>#j#</td></cfloop>
</tr>
</cfloop>
</cfif>
</cfloop>
jbird5k
jbird5kAuthor
Inspiring
March 3, 2009
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.

J
Inspiring
March 3, 2009
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 ...
</cfloop>

Inspiring
March 3, 2009
So what is your question ? (ie Which part are you having difficulty with)