SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    pulling elements from a list of undefined length

    I have a list that I want to seperate out the contents to store in seperate variables.
    <cfset x = #ListQualify(form.campyear1,",")#>
    <CFLOOP From = "1" TO = "#ListLen(x)#" INDEX = "Counter">
    <cfoutput>#ListGetAt(x, Counter)#</cfoutput>
    </cfloop>

    this will output what i need, but instead I want to store each item in a new variable. I have no clue where to go from here any help would be appreciated.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by shaggysc96 View Post
    I want to store each item in a new variable.
    and what are you going to do with the variables?

    whatever it is, you could probably just use the list element instead
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can use a dynamically named variable:

    <cfset "Var#Counter#" = ListGetAt( x, Counter )# />

    So if the counter is 2008, a variable called Var2008 will now exist in the VARIABLES scope with the value of your ListGetAt() method.

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then if possible I want to insert each variable into a database, where as the first element inserted, for example var1 = the first value in the list.

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    could you show the table layout?

    i am concerned because these elements came from a comma-delimited list

    hopefully you are inserting each value into a separate table row

    in any case, you don't need the variables, just use the list elements
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •