> Yes, you are right, I would like to do it in two queries 
> also, I don't think what you described would work (but please 
> correct me if I am wrong). What I want is:
> 
> [icon] Notice    (query one output)
>      [subIcon] subdocument  (query two output)
>      [subIcon] subdocument  (query two output)
>      [subIcon] subdocument  (query two output)
> [icon] Notice    (query one output   etc.....)
>      [subIcon] subdocument
>      [subIcon] subdocument
> [icon] Notice
>      [subIcon] subdocument
>      [subIcon] subdocument
>      [subIcon] subdocument
>      [subIcon] subdocument
>      [subIcon] subdocument
> 
> etc. To make this it seems like I have to be inside the loop 
> of a query output, getting the noticeID to do the query for the 
> sub documents. Then it seems like I would need to do a nested 
> cfoutput to get the returned sub documents to print. Maybe though 
> there is a much easier way to do all this.

You can do this by using CFLOOP to loop over the outer query (notices), then
execute a nested query within the loop for each set of subdocuments.
However, you can make this easier for yourself in all likelihood by simply
having one query which retrieves all notices and their related subdocuments,
then looping over its records using the CFOUTPUT tag and its GROUP
attribute, which will allow you to display each notice, then all of the
subdocuments associated with that notice. Your query might look like this:

<cfquery name="qNotices" datasource="ds">
        SELECT  n.notice,
                        s.subdocument
        FROM            notices n,
                        subdocuments s
        WHERE           n.notice_id = s.notice_id
        ORDER BY        n.notice
</cfquery>

Note that in the above example, only notices with associated subdocuments
would be retrieved. If you wanted notices even if they didn't have any
subdocuments, you'd need an outer join instead of an inner join:

WHERE           n.notice_id *= s.notice_id

In either case, when you wanted to output your records, it might look like
this:

<cfoutput query="qNotices" group="notice">
        #Notice#<br>
        <cfoutput>
                #Subdocument#<br>
        </cfoutput>
        <br>
</cfoutput>

Note the nested CFOUTPUT tags above. This is made possible by the use of the
GROUP attribute in the first CFOUTPUT tag, which allows you to output a data
hierarchy. This will output each notice, followed by the subdocuments
associated with that notice.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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