• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

working with Lists

Participant ,
Mar 03, 2009 Mar 03, 2009

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

519

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Mar 03, 2009 Mar 03, 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>

Votes

Translate

Translate
Valorous Hero ,
Mar 03, 2009 Mar 03, 2009

Copy link to clipboard

Copied

So what is your question ? (ie Which part are you having difficulty with)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 03, 2009 Mar 03, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 03, 2009 Mar 03, 2009

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 03, 2009 Mar 03, 2009

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 03, 2009 Mar 03, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2009 Mar 03, 2009

Copy link to clipboard

Copied

LATEST
If you have the opportunity, you should alter that table so that each list element of the response is in it's own field.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation