Skip to main content
Inspiring
January 25, 2012
Question

valueList?

  • January 25, 2012
  • 3 replies
  • 2650 views

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



This topic has been closed for replies.

3 replies

BKBK
Community Expert
Community Expert
January 26, 2012

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.

ilssac
Inspiring
January 25, 2012

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.

Inspiring
January 25, 2012

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

kt03Author
Inspiring
January 25, 2012

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

ilssac
Inspiring
January 25, 2012

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>