First of all, there is huge overhead in doing this, so I hope this isn't
anything you intend to use for a production application. There are plenty
of ways to accomplish this faster. That being said, try this:
<cfif isDefined("URL.ColOptions")>
<!--- Parse out options and store in a structure. --->
<cfset aColOpts = ArrayNew(1)>
<cfloop list="#URL.ColOptions#" index="Cols" delimiters=",">
<cfset foo = StructNew()>
<cfloop list="#Cols#" index="Opts" delimiters=";">
<cfif #ListLen(Opts,":")# GT 1>
<cfset Result = StructInsert(foo,
ListFirst(Opts,":"), ListLast(Opts,":"))>
</cfif>
</cfloop>
<cfset temp = arrayAppend(aColOpts,foo)>
</cfloop>
</cfif>
ps. if you always know that NAME and WIDTH will be the struct keys the
problem becomes much simpler
Bryan Love Macromedia Certified Professional
Internet Application Developer
Telecommunication Systems Inc.
[EMAIL PROTECTED]
"A wise man speaks when he has something to say, a fool speaks when he has
to say something."
-----Original Message-----
From: Snyder, Jason [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 20, 2001 9:06 AM
To: CF-Talk
Subject: Please Help: Parsing URL into Array and structure
I am working on parsing a URL string and storing it in an array of
structures. I am to the point where it works to a certain extent, but not
to the point where I need it. To be more specific I am passing a string
that should be parsed into two structure elements in the array. The data
seems to be inserted, but but when I try to access the structure key 'name'
in array element 1 it comes up while array element 2 does not. Here is the
Query string that I am passing:
MaintenanceEditTable.cfm?table=tlkpStatus&tableCols=Statno,
Status&ColOptions=name:Statno;width:100, name:Status;width:300
In this URL string I pass the database table name. Then I pass table
columns. The I pass column options in the following format:
1. Comma delimits columns.
2. Semicolon delimits options for a column.
3. Colon delimits option / value pair.
4. Name option is required. (Specifies name of column.)
Here is the code that parses ColOptions (note that cfoutput is only used to
display debugging information):
<cfif isDefined("URL.ColOptions")>
<!--- Parse out options and store in a structure. --->
<cfset aColOpts = ArrayNew(1)>
<cfset aColTemp = ArrayNew(1)>
<cfset iCntLoop=1>
<cfloop list="#URL.ColOptions#" index="Cols" delimiters=",">
<cfset aColOpts[iCntLoop] = StructNew()>
<cfloop list="#Cols#" index="Opts" delimiters=";">
<cfif #ListLen(Opts,":")# GT 1>
<cfset aColTemp[1] =
#ListGetAt(Opts,1,":")#>
<cfset aColTemp[2] =
#ListGetAt(Opts,2,":")#>
<!--- <cfoutput>#aColTemp[1]#,
#aColTemp[2]#;</cfoutput> --->
<cfset Result =
Evaluate("StructInsert(aColOpts[iCntLoop], '#aColTemp[1]#',
'#aColTemp[2]#')")>
<cfoutput>#iCntLoop#, #aColTemp[1]#,
#aColOpts[iCntLoop][aColTemp[1]]#; </cfoutput>
</cfif>
</cfloop>
<cfset iCntLoop=iCntLoop+1>
</cfloop>
</cfif>
When I run this I interpreted the debugging information as meaning that
values where entered and read back out of the first two positions in the
array. Please tell me if you have a different interpretation or find
something wrong with mine.
Here is the code that ColdFusion choked on:
<cfloop FROM="1" TO="#ArrayLen(aColOpts)#" index="iCntDF">
<cfoutput>#iCntDF#, #aColOpts[iCntDF].name#;</cfoutput>
</cfloop>
For me this seemed to go through the first position in the array and read
the struct value, but it choked on the second position in the array.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community. http://www.fusionauthority.com/ads.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists