Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFTREE and CFLOOP...pls help! 1

Status
Not open for further replies.

kuolung

Programmer
Sep 2, 1999
51
US
ok, here is what i have:


<cfquery name=&quot;orgs&quot; datasource=&quot;#mydsn#&quot;>
select distinct organization as org
from orgs
order by 1
</cfquery>

<cfquery name=&quot;groups&quot; datasource=&quot;#mydsn#&quot;>
select distinct organization as org, organizational_group as group
from orgs
where organization = '#orgs.org#'
order by 1, 2
</cfquery>


<cfform action=&quot;mytree_action.cfm&quot;>
<cftree name=&quot;mytree&quot;
height=&quot;1600&quot;
width=&quot;200&quot;
bold=&quot;No&quot;
italic=&quot;No&quot;
border=&quot;No&quot;
hscroll=&quot;No&quot;
vscroll=&quot;No&quot;
required=&quot;No&quot;
completepath=&quot;Yes&quot;
appendkey=&quot;Yes&quot;
highlighthref=&quot;Yes&quot;>

<cftreeitem value=&quot;Organization&quot;
display=&quot;Organization&quot;
img=&quot;pls.gif&quot; imgopen=&quot;mns.gif&quot;>

<cfloop query=&quot;orgs&quot;>
<cftreeitem value=&quot;#orgs.org#&quot;
display=&quot;#orgs.org#&quot;
parent=&quot;Organization&quot;
img=&quot;pls.gif&quot; imgopen=&quot;mns.gif&quot;>

</cfloop>

<cfloop query=&quot;groups&quot;>
<cftreeitem value=&quot;#groups.group#&quot;
display=&quot;#groups.groups#&quot;
parent=&quot;#orgs.org#&quot;
img=&quot;mns.gif&quot;>
</cfloop>
</cftree>
</cfform>


this is 3 level tree and this is the result i want:
+Organization
+Group1
-Sub-Group1.1
-Sub-Group1.2
- ...
+Group2
-Sub-Group2.1
-Sub-Group2.2
-...
+....

However, the problem I have for now is ONLY Group1 works and got expanded into sub-groups (by clicking on plus sign/image), all Group2 and the rest of the Group are unclickable, and I can't see any sub-groups below them. how do put the loop so that ALL Group work and can be expanded??? thank you.....



 
Hi Sakura,

Great Code, I like the idea. I see a possible problem in your second CFloop check this out:

<cfloop query=&quot;groups&quot;>
<cftreeitem value=&quot;#groups.group#&quot;
display=&quot;#groups.groups#&quot;
parent=&quot;#orgs.org[currentrow]#&quot;
img=&quot;mns.gif&quot;>
</cfloop>

When you do a CFLOOP with a Query it only steps through the query that you hand it. The reference to #orgs.org# was not being stepped it was always pointing to #orgs.org[1]# that's why only the first one worked. I'm not sure exactly how your database is set up but it looks like that will work fine.

Let me know if that works.


 
hello tlhawkins,

thanks however, this is the result i get as i add [currentrow] into my code:

+Organization
+Group1
-Sub-Group1.1
+Group2
-Sub-Group1.2
+Group3
-Sub-Group1.3
+....

so it like reading only the subgroups within Group1 and loop each subsgroup on under different Group...Do you have any ideas why it does that? any other solutions? Thank you.

well, this is how my database look like, you can see from my 1st post, the Group and Sub-Group are from the same table &quot;Orgs&quot;, one Group can have more than 1 Subgroup (side note: organziation can have more than 1 Group, but i don't care about the upper level Org).

So, please help me again if you know other approach to this problem...thank so much.

sakura
 
Sakura
In the second loop the parent should be
parent=&quot;#groups.org#&quot;

not #orgs.org#
 
Ram123,
it still doens't work, the result i got is the same as my orignal code (1st post).
please help again....thanksssss
 
HEY Sakura,

I just noticed something else, I didn't even look before but in your Query called &quot;groups&quot; the line:

where organization = '#orgs.org#'

is limiting your Query to the organization represented by the first record of Orgs.org . Test this by trying to output the Query all by itself. Check that your Query is gathering the correct data. If it isn't then you can put the Query inside the loop with the Org Query like this:

<cfloop Index=&quot;x&quot; from=&quot;1&quot; to=&quot;#orgs.recordcount#&quot;>

<cfquery name=&quot;groups&quot; datasource=&quot;#mydsn#&quot;>
select distinct organization as org, organizational_group as group
from orgs
where organization = '#orgs.org[x]#'
order by 1, 2
</cfquery>

<cfloop query=&quot;groups&quot;>
<cftreeitem value=&quot;#groups.group#&quot;
display=&quot;#groups.groups#&quot;
parent=&quot;#orgs.org[x]#&quot;
img=&quot;mns.gif&quot;>
</cfloop>
</CFLOOP>

If that doesn't work send me a picture of your database setup and I'll spend some time with it. By the way, exactly where is &quot;groups.groups&quot; set (for the Display field)? In the Query I only see &quot;groups.group&quot; Might not be important but I was curious.



 
Hello tlhawkins,

thanks thank you so very much, it works now. I'm so happy. Glad to have all the experts in this forum.!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top