loop over flash array in cfc..

Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default loop over flash array in cfc..

    hi.

    i'm passing a simple array from flash to a cfc and trying to understand how to
    loop over it using an index loop to make my sql inserts. i just don't know the
    proper way to loop over the array. here's the basic format of my array from
    flash:

    myArray = ["one", "two", "three'];

    what i want to do is insert each element of this array into a separate field
    in my table.

    and this is what i'm doing in the cfc:

    any help on how to just get started is very much appreciated. thank you.



    <cffunction name="logStuff" access="remote">

    <cfargument name="myArray" type="array" required="yes">

    <cfset mLen = ArrayLen(myArray)>

    <cfloop index="i" from="0" to="#mLen#">

    <cfquery name="logStuff" datasource="myDB">
    INSERT INTO myTable( id,
    subject,
    body,
    field1,
    field2,
    field3 )

    VALUES ( '??',
    '??'',
    '??',
    '??',
    '??'
    '??')

    </cfquery>

    </cfloop>

    </cffunction>

    fu-meng Guest

  2. Similar Questions and Discussions

    1. loop through array to build a new array
      If I combine the following 2 functions (accesses by clicking a checkbox), as result the new array does not contains all items that matches the...
    2. cannot loop the array
      I have 2 questions regarding arrays: 1) we need to define the size of the array, there is no dynamic array concept? i.e. the following define the...
    3. Array Loop
      Please help me to debug: <cfquery name="qSelectPwd" datasource="#Application.AppDSN#"> select password from tablename </cfquery> <!---...
    4. if/loop/array question
      I'm trying to display an add or delete button dependent upon logged in user and I can't figure it out. Can someone please help with the...
    5. array data matches but array created in loop doesn't work
      I have the exact same data in two arrays, but only the array created like so will work: $spaw_imglibs = array( array( 'value' =>...
  3. #2

    Default Re: loop over flash array in cfc..

    update: i'm able to pull one of the items in my array but the problem is that i
    have 3 elements in my array and only 1 record is being created in my database.
    here's my updated code:

    <cffunction name="logStuff" access="remote">

    <cfargument name="myArray" type="array" required="yes">

    <cfset mLen = ArrayLen(myArray)>

    <cfloop index="i" from="0" to="#mLen#">

    <cfquery name="logStuff" datasource="myDB">
    INSERT INTO myTable( id,
    subject,
    body,
    field1 )

    VALUES ( 'id',
    'subject',
    'body',
    '#arguments.myArray[i]#' )

    </cfquery>

    </cfloop>

    </cffunction>

    fu-meng Guest

  4. #3

    Default Re: loop over flash array in cfc..

    got it. i was overwriting a key in my database and that was causing problems. my cf code was correct.

    thanks for following along.

    fumeng.
    fu-meng Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139