8 Replies Latest reply: Jan 26, 2012 1:44 AM by BKBK RSS

    valueList?

    kt03 Community Member

      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

        • 1. Re: valueList?
          Adam Cameron. Community Member

          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

          • 2. Re: valueList?
            ilssac Community Member

            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.

            • 3. Re: valueList?
              kt03 Community Member

              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

              • 4. Re: valueList?
                ilssac Community Member

                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>
                
                • 5. Re: valueList?
                  kt03 Community Member

                  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

                  • 6. Re: valueList?
                    ilssac Community Member

                    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>

                    • 7. Re: valueList?
                      BKBK MVP

                      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>

                      • 8. Re: valueList?
                        BKBK MVP

                        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.