Bryan Love wrote:

> wow.
>
> First of all it looks like you've forgotten to use #innerloop# anywhere in
> your code.  The query is hard-coded to use [1] and [2] from the second
> dimension of your array.  Perhaps each item in the first dimension contains
> a sub-array of only two items (documentID and headingID).  If this is the
> case then why are you looping over the second dimension?  This would cause
> the exact same query to be run twice, outputting the same single record each
> time.  If this is the case then just eliminate the inner CFLOOP and remove
> GROUP= from the CFOUTPUT.

The innerloop was a leftover from the code in Chapter 9 of the Developing Web 
Applications with ColdFusion book.
Where I hard coded the 1 and 2 had been where innerloop would've been. I knew that 
column 1 was headingids and
column 2 was docids, but I needed to loop through all the pairs of ids to find and 
output the actual names of
documents and headings. I took the innerloop and group out and got the same result was 
before.

>
> Secondly, putting a query inside a double nested loop is not a very good
> idea.  CFOUTPUT was given a GROUP attribute to avoid this kind of situation;
> it's just a matter of learning to use it correctly.  It looks like you are
> basically trying to  print the collection of documents stored in the
> original array.

The only reason the query is inside the loop is so I can refer to the elements inside 
the array in my query. I'm
not trying to use cfloop to group it, just use it to retreive the ids for the array so 
the query can use them to
get the names (and other associated information). I don't know how else to retreive 
the information in the array
without looping.


> a query like this would be much more efficient:
>
> SELECT ...
> FROM ...
> WHERE document.documentid IN (...docID list...)
>         AND headingid IN (...headingID list...)
>         AND (join document and heading somehow here so ensure the proper
> records are related to each other)
>         and document.nameno=articlenames.nameno
>         and document.documentid=article.documentid
>         order by headingname, articlename
>
> Then you can use the GROUP attribute in your CFOUTPUT to control the output
>
> FYI:  GROUPs can be nested...
>
> <cfoutput query="myQuery" group="group1">
>         <cfoutput group="group2">
>                 <cfoutput>
> ....
>

That last AND (join document and heading somehow here so ensure the proper records are 
related to each other) is
the problem. I can't figure out how to do it without cfloop. The two columns of the 
array were originally 2
query-driven lists that I converted into an array. So I thought I'd use listgetat to 
synchronize the position in
the lists, but that would require using a loop to go through the lists.

Any ideas on how to sync the lists without looping?

Thanks!
Jen


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to