0 Replies Latest reply on Oct 3, 2006 10:31 AM by funnyface320

    CFC and Arrays

    funnyface320
      I have created a component that functions normally with a simple layout ex: <cfargument name="var1" type="string"...><cfargument name="myVar" type="string" . . .>
      Goal: to create a component that allows me to insert users information into a database, not knowing how many insertions that will need or how many fields they will need to insert into.
      Attempted: I have tried to create create 4 additional variables that will allow the user to put in the number of insertions they will need. ex: <cfarg name="nStartAt" type="numeric" . . .> <cfarg name="nEndAt". . .> <cfarg name="nStartAt2" type="numeric" . . .> <cfarg name="nEndAt2". . .> both nStartAt variables start at the beginning of the array so they are set to equal 1. then both endAt variables will end at what the user tells it to end.
      Sample of Attempt: forgive me if i miss a few steps i have changed my code since then, therefore I can not cut and paste.
      <cfquery datasource. . .>
      INSERT INTO myTable (<cfloop from="#arguments.nStartAt#" to="#arguments.nEndAt#" index="i"> #argument.myVar # <cfif #i# LT 2>,</cfif><!-- that statment adds the common after the variable--></cfloop>
      VALUES(<cfloop from="#arguments.nStartAt2#" to="#arguments.nEndAt2#" index="i">#argument.myValue
      # <cfif #i# LT 2>,</cfif></cfloop>
      </cfquery>

      Errors Received:when i first tried in the errors i could see that it was trying to insert it into the database but the it was trying to insert it as value1 value2 instead of the actual value, saying myVar1 was undefined. Then it pretty much went downhill from there. Then later it appeared it did not like that myVar was being treated like an Array, after i set the array above the cffunction tag ex: <cfset myVar = ArrayNew(1)> then in the page code i created an array for that data then gave the cfinvokeargument name="myVar" value="being the array i created in the other page"

      If anyone has any idea how i can reach my goal please email me! or leave comments email address funnyface320 I can be instant messaged at yahoo using the same name. Hopefully I will figure this problem out but if not I would love the help!

      Thanks to all those who reply and see this!