Skip navigation
Currently Being Moderated

valueList?

Jan 25, 2012 8:38 AM

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



 
Replies
  • Currently Being Moderated
    Jan 25, 2012 8:41 AM   in reply to kt03

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 25, 2012 8:55 AM   in reply to kt03

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 25, 2012 8:58 AM   in reply to kt03

    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>
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 25, 2012 9:30 AM   in reply to kt03

    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>

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 26, 2012 1:43 AM   in reply to kt03

    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>

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 26, 2012 1:44 AM   in reply to kt03

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points