INSERT INTO AMUSER.HD_CATEGORY (CATEGORYID, CATEGORYNAME, SURVEYID) VALUES(#qSimpleQuery.CATEGORYID#, '#qSimpleQuery.CATEGORYNAME#', #qSimpleQuery.SURVEYID#) Do you know how I can use the structure function to accomplish the same thing? [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => murpg [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> INSERT INTO AMUSER.HD_CATEGORY (CATEGORYID, CATEGORYNAME, SURVEYID) VALUES(#aPersons[i].CATEGORYID#, '#aPersons[i].CATEGORYNAME#', #aPersons[i].SURVEYID#)
[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => BSterner [ip] => joenobody720@ex [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 5 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> Structure looping in a UDF - Coldfusion - Advanced Techniques

Structure looping in a UDF - Coldfusion - Advanced Techniques

I have a user defined function which is programed to take multiple arguments, and it is taking multiple arguments; but it is only writing one row to the structure. I want it to write all rows. Do you have any thoughts on how I might accomplish this? All you need to do to run this code is to copy and paste. <cfif ISDefined("form.categoryid")> <cffunction name="CreateStruct" returntype="Struct" output="false"> <cfset Var MyStruct = Arguments> <cfreturn MyStruct> </cffunction> <cfloop from="1" to="#listlen(form.categoryName)#" index="k"> <cfset currID = listGetAt(form.CATEGORYID, k)> <cfset currName = listGetAt(form.categoryName, k)> <cfset currSur = listGetAt(form.SURVEYID, k)> <cfset Person =CreateStruct(CATEGORYID = #currID#, CATEGORYNAME ...

  1. #1

    Default Structure looping in a UDF

    I have a user defined function which is programed to take multiple arguments,
    and it is taking multiple arguments; but it is only writing one row to the
    structure. I want it to write all rows. Do you have any thoughts on how I
    might accomplish this?
    All you need to do to run this code is to copy and paste.

    <cfif ISDefined("form.categoryid")>
    <cffunction name="CreateStruct" returntype="Struct" output="false">
    <cfset Var MyStruct = Arguments>
    <cfreturn MyStruct>
    </cffunction>
    <cfloop from="1" to="#listlen(form.categoryName)#" index="k">
    <cfset currID = listGetAt(form.CATEGORYID, k)>
    <cfset currName = listGetAt(form.categoryName, k)>
    <cfset currSur = listGetAt(form.SURVEYID, k)>
    <cfset Person =CreateStruct(CATEGORYID = #currID#, CATEGORYNAME =
    '#currName#', SURVEYID = #currSur#)>
    </cfloop>
    <cfdump var="#Person#">
    <cfdump var="#listlen(form.categoryName)#">
    <cfdump var="#k#">
    </cfif>

    <form action="" method="post">
    <input name="CATEGORYID" type="hidden" value="21">
    <input name="CATEGORYID" type="hidden" value="22">
    <input name="CATEGORYNAME" type="hidden" value="Support in time">
    <input name="CATEGORYNAME" type="hidden" value="This is great">
    <input name="SURVEYID" type="hidden" value="4">
    <input name="SURVEYID" type="hidden" value="4">
    <input name="" type="submit">
    </form>

    murpg Guest

  2. #2

    Default Re: Structure looping in a UDF

    You can't have duplicate key names for your struct. What is it you want - 1
    Struct which contains all the values or 2 structs that contains each set? If
    it's the former, you'll have to create key names based on something unique to
    each set (Example, categoryid). If it's the latter, you can store an array of
    structs. Not sure why you're using a function here. Seems unnecessary.

    BSterner Guest

  3. #3

    Default Re: Structure looping in a UDF

    This is mearly a tester to get to something more complicated. I was using a
    query for this. Here is the code I was using.
    <!--- create a new query with 3 cols --->
    <cfset qSimpleQuery = QueryNew("CATEGORYID, CATEGORYNAME, SURVEYID")>
    <cfset thisPos = 1>
    <cfloop index="i" list="#form.categoryId#" delimiters=",">
    <cfset newRow = QueryAddRow(qSimpleQuery)>
    <cfset QuerySetCell(qSimpleQuery, "CATEGORYID", "#i#")>
    <cfset thisCatName = ListGetAt(form.CategoryName, thisPos , ",")>
    <cfset QuerySetCell(qSimpleQuery, "CATEGORYNAME", "#thisCatName#")>
    <cfset thisSurID = ListGetAt(form.surveyid, thisPos , ",")>
    <cfset QuerySetCell(qSimpleQuery, "SURVEYID", "#thisSurID#")>
    <cfset thisPos = #thisPos# + 1>
    </cfloop>

    <cfloop query="qSimpleQuery">
    <cfquery datasource="#Application.DSN#">
    INSERT INTO AMUSER.HD_CATEGORY (CATEGORYID, CATEGORYNAME, SURVEYID)
    VALUES(#qSimpleQuery.CATEGORYID#, '#qSimpleQuery.CATEGORYNAME#',
    #qSimpleQuery.SURVEYID#)
    </cfquery>
    </cfloop>

    Do you know how I can use the structure function to accomplish the same thing?

    murpg Guest

  4. #4

    Default Re: Structure looping in a UDF

    I forgot the most important thing which is what i want which 1 structure with 2
    rows and 3 columins? If I have to write and ARRAY into each structure to get
    what I am looking for can you show me how to do that? Thanks,

    murpg Guest

  5. #5

    Default Re: Structure looping in a UDF

    What is wrong with using the query data structure?

    I forgot the most important thing which is what i want which 1 structure with
    2 rows and 3 columins?

    A struct is simply a collection of key/value pairs (Eg: "FirstName" => "Joe",
    "LastName" => "Doe"). It doesn't have "rows" and "columns" per say.

    Without knowing exactly what you're doing, it's hard to say what best fits
    your situation, but to me this whole business of using stucts, lists and arrays
    could be simplified. If a db insert is the ultimate goal, this seems like
    overkill.

    Now, that being said, if you still are stuck on the struct, here's an example
    (using your code) to store the information as an array of structs.


    <cfif isDefined("form.categoryid")>
    <cfdump var="#form#" /><br>
    <cffunction name="createStruct" returntype="struct" output="false">
    <cfset var myStruct = arguments />
    <cfreturn myStruct />
    </cffunction>

    <cfset aPersons = arrayNew(1) />
    <cfloop from="1" to="#listlen(form.categoryName)#" index="k">
    <cfset currID = listGetAt(form.CATEGORYID, k) />
    <cfset currName = listGetAt(form.categoryName, k) />
    <cfset currSur = listGetAt(form.SURVEYID, k) />
    <cfset aPersons[k] = createStruct(CATEGORYID = currID, CATEGORYNAME =
    currName, SURVEYID = currSur) />
    </cfloop>

    <!--- Dump data structure --->
    <cfdump var="#aPersons#" label="person" />
    <cfdump var="#listlen(form.categoryName)#" label="listlen(form.categoryName)"
    />
    <cfdump var="#k#" label="k" />

    <!--- Loop through struct and update db --->
    <cfloop from="1" to="#arrayLen(aPersons)#" index="i">
    <cfquery datasource="#Application.DSN#">
    INSERT INTO AMUSER.HD_CATEGORY (CATEGORYID, CATEGORYNAME, SURVEYID)
    VALUES(#aPersons[i].CATEGORYID#, '#aPersons[i].CATEGORYNAME#',
    #aPersons[i].SURVEYID#)
    </cfquery>
    <br>
    </cfloop>
    </cfif>

    BSterner Guest

Similar Threads

  1. looping over a structure using cfscript
    By zubair in forum Coldfusion - Advanced Techniques
    Replies: 5
    Last Post: November 29th, 06:35 PM
  2. basic looping help (want to stop looping in layer)
    By hamish@sullivanparkmedia.com in forum Macromedia Flash
    Replies: 2
    Last Post: February 22nd, 05:34 AM
  3. Replies: 1
    Last Post: May 1st, 03:24 PM
  4. Looping through a structure with duplicate key names
    By Fychan66 in forum Coldfusion - Getting Started
    Replies: 1
    Last Post: June 13th, 11:47 AM
  5. Process folder structure into new structure
    By Bryan in forum PERL Beginners
    Replies: 3
    Last Post: April 27th, 04:46 AM

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
  •