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

valueList?

Explorer ,
Jan 25, 2012 Jan 25, 2012

Copy link to clipboard

Copied

i have 2 text boxes from the form for user to enter an email address.  those are not requied, meaning sometime i have one email, or two emails.  I stored both emails into one field in the table. such as: test@yahoo.com. hello@gmail.com

On the edit page, i want to retireve both emails but each email will go into one text box.

i am thinking about values list

<cfset emailList = ValueList(qry.email ,  ',' />

but i am getting an error "Complex construct are not supported with fuction ValueList."  and i am not sure if i am going to the right direction?

thanks

kt

TOPICS
Getting started

Views

2.3K

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 ,
Jan 25, 2012 Jan 25, 2012

Copy link to clipboard

Copied

I presume there's a typo in your code there because that would not compile as is.

What's the value of qry.email?

--

Adam

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
Explorer ,
Jan 25, 2012 Jan 25, 2012

Copy link to clipboard

Copied

this code returned sperate such as

<cfloop index ="ListElement" list ="#qry.email#>

<cfoutput>#ListElement#</cfoutput>

</cfloop>

test@yahoo.com

hello@gmail.com

but i don't know how to count that how many email is returned and put each into each text box

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 ,
Jan 25, 2012 Jan 25, 2012

Copy link to clipboard

Copied

1) The listLen() function will tell you how many items are in a list.

2) Where you have <cfoutput>#listElement#</cfoutput>  output a text box.

I.E.

<cfoutput><input type="text" name="email" value="#listElement#"/></cfoutput>

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
Explorer ,
Jan 25, 2012 Jan 25, 2012

Copy link to clipboard

Copied

already try that but it only output the last one.  I think what i am going to do is use the listFirst(), ListLast() and LitGetAt() .  ListGetat() to get the second email from the list, since i have three text boxes with three emails  but how can i count for the postion to get email2?

test@nody.com, hello@gmail.com, today@one.com

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 ,
Jan 25, 2012 Jan 25, 2012

Copy link to clipboard

Copied

kt03 wrote:

already try that but it only output the last one. 

Then something is not working as I would expect it to work.  But I don't really know wht you tried, because you didn't actually show what you tried.

You would use 2 to get at the send item in a list.  ColdFusion is one based so the first item in a list is 1, the second is 2, and so on.

I.E. <cfoutput>#listGetAt(qry_email.email,2)#</cfoutput>

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
Community Expert ,
Jan 26, 2012 Jan 26, 2012

Copy link to clipboard

Copied

kt03 wrote:

this code returned sperate such as

<cfloop index ="ListElement" list ="#qry.email#>

<cfoutput>#ListElement#</cfoutput>

</cfloop>

test@yahoo.com

hello@gmail.com

but i don't know how to count that how many email is returned and put each into each text box

Looping across a list occurs automatically. You don't need to know how many list-elements there are. However, as Ilssac says, you could use listLen(qry.email) where needed (I have assumed the delimiter is a comma).

Your answer is almost there! You could do the following in a form:

<cfset emailCount = 1>

<cfset emailList = valueList(qry.email)>

<cfform>

<cfloop index ="ListElement" list ="#emailList#">

    <cfoutput><cfinput type="text" name="email_&#emailCount#" value="#ListElement#"></cfoutput><br>

    <cfif emailCount LT listLen(emailList)>

        <cfset emailCount = emailCount+1>

    </cfif>

</cfloop>

</cfform>

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 ,
Jan 25, 2012 Jan 25, 2012

Copy link to clipboard

Copied

The purpose of the ValueList() function is to take values in a field from multiple records in the record set and make a list out of them.  Which, if you had a well normalize database design, you would be retreiving.

I.E. qry_email

IDEMAIL
1test@abc.com
2foobar@one.org
3joe@nobody.net

<cfoutput>#valueList(qry_email.email)#</cfoutput>

will return "test@abc.com,foobar@one.org,joe@nodbody.net".

You have a un-normalized table field that contains a list of values.  I presume you would like to process the items in that list individually.

The list functions are probably what you would like to use.

I.E.

<cfloop list="#qry_email.email#" item="x">

<cfoutput>#x#</cfoutput>

</cfloop>

There are many other list functions you can use, listFirst(), listLast(), listGetAt(), etc.

Of course the professional in me would suggest that you properly normaize your database design if at all possible.

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
Community Expert ,
Jan 26, 2012 Jan 26, 2012

Copy link to clipboard

Copied

LATEST

kt03 wrote:

<cfset emailList = ValueList(qry.email ,  ',' />

but i am getting an error "Complex construct are not supported with fuction ValueList."  and i am not sure if i am going to the right direction?


That line misses a closing bracket.

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