Looping over a structure into a query

Oct 29, 2008

Thanks to CF-talk, have worked out a way to get my posted form structs into queries a little more easily; It's the "#testStruct["UrlText_" & counter]#" syntax which was the key for me.. posted here for my own reference!

<cfset testStruct = structnew() />
<cfset testStruct.LinkText_1 = "Linktest1" />
<cfset testStruct.LinkText_2 = "Linktest2" />
<cfset testStruct.LinkText_3 = "Linktest3" />
<cfset testStruct.UrlText_1 = "Urltest1" />
<cfset testStruct.UrlText_2 = "Urltest2" />
<cfset testStruct.UrlText_3 = "Urltest3" />
<cfset TempLinkQ=QueryNew("linkname,url", "varchar,varchar")>

<cfdump var="#testStruct#" />

<cfset counter =1>
<cfloop list="#structKeyList(testStruct)#" index="key">
<cfif key CONTAINS "linktext" AND len(teststruct[key]) GTE 1>
<cfoutput>
<cfset QueryAddRow(TempLinkQ, 1)>
<cfset QuerysetCell(TempLinkQ, "linkname", "#testStruct["linkText_" & counter]#")>
<cfset QuerysetCell(TempLinkQ, "url", "#testStruct["UrlText_" & counter]#")>
</cfoutput>

<cfset counter=(counter+1)>
</cfif>
</cfloop>

<cfdump var="#TempLinkQ#">

Comments

Write your comment



(it will not be displayed)





About Tom

Tom is the author of this blog and the brains behind OxAlto Design More ...

Categories

Monthly Archives

Links

Tag Cloud

coldfusion web-development internet misc music cfwheels railo drupal vps chchchoir blueprintcss jquery mangoblog flex ipod mac wowza demos flash flickr google hinkseystudio itunesu wallpapers wordpress

Feeds