• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

tree question --challenge

I have question regarding tree. Please look at this url.

http://www.nlm.nih.gov/mesh/2002/MBrowser.html
I would like to create this tree structre. Look AT the drop down. How
can i create the drop down with (+) sign if they have more child
etc...
Do the search or Nevigate from tree tops. see this drop down menu.
Once i click on the drop down it will expened in the same page
..
how can we do in coldfusion ... thnaks

0
ts20031
Asked:
ts20031
  • 5
  • 4
1 Solution
 
substandCommented:
I don't think this is as easy as 50 points would indicate, but i'll give it a shot anyway.

even though there's nothing on that page that you are talking about (that i saw), i think i still have an idea of what you are looking for.

first, you'll need to implement your database (assuming these records are all in one table) as you normally would, but with a field called parentID, and store in this field the parent's id.  the "id" field should be the primary key of the table.  if the "parentID" is null, we will assume that it is a "root".  order all queries in descending order of id.

then, you'll need to basically implement a stack, and loop through everything in a conditional loop that continues until the stack is empty.

here's the basic algorithm:

1) get parent id's and put in stack, where the last id is the first one in the stack.  you can implement the stack as a list where all inserts and removals from the list are done at position 1.

2) begin loop through the stack while !isempty(stack)
3) curID=remove first element from stack
4) query db to find curID's diplay info
4) query db to find curID's children
5) add children to stack, also in decending order
6) display curID, and a [+] if there are children
7) end loop

if you want the hidden stuff you talk about, you'll need to use javascript. for javascript info, look at http://javascript.about.com, or do a seach on google for "dhtml" or "dhtml javascript" or "dhtml javascript dynamic menus"

you can find plenty of free source code that way to implement the hidden/show on click stuff.  

of course, if you do that, then you'll populate the javascript data, rather than "display" in the loop.  then you'll use the javascript to display.


here's a clip of a concrete example of the loop in coldfusion that I wrote for a message board that will give "infinite indention" to replies of a parent message:

<!--- get root ids ----->
            <cfquery name="root" datasource="#DbName#" dbtype="ODBC" cachedwithin="#CreateTimeSpan(0,0,IIF(Flush,0,QueryCacheTime),0)#">
            SELECT EntryID FROM connectMessages  
            WHERE RoomID = <cfif MultiRoom>#RoomID#<cfelse>1</cfif> AND PostNum BETWEEN #EndPostNum# AND #PostNum#
            AND ReplyTo is NULL
            ORDER BY PostNum desc, Thread Asc
            </cfquery>
            <cfloop query="root">
                  <cfif currentRow is 1>
                        <cfset stack=entryID>
                  <cfelse>
                        <cfset stack=listinsertat(stack, 1, EntryID)>                   
                  </cfif>
            </cfloop>
            <cfset printlist="0">
            <cfset donelist="0">
            <cfset count=0>
            <cfset endsub=1>
      <cfloop condition="listlen(stack) is not 0">
                  
            <cfquery name="list" datasource="#DbName#" dbtype="ODBC" cachedwithin="#CreateTimeSpan(0,0,IIF(Flush,0,QueryCacheTime),0)#">
            SELECT PostNum, Thread, Author, CreateDate, Title, EntryID, ThreadCount, ThreadEnd FROM connectMessages  
            WHERE entryID=#listgetat(stack,listlen(stack))#
            </cfquery>
            <cfif not listcontains(printlist,listgetat(stack,listlen(stack)))>
                  <cfset indent=0>
                  <cfoutput query="list">
                        <cfset count=count+1>
                        <tr <CFIF count MOD 2 eq 1>bgcolor="white"<CFELSE>bgcolor="#RowColor#"</cfif> ><td height="20" valign=middle nowrap>#DefaultFont#&nbsp;<cfif EntryID eq Url.EntryID><b>#Title#</b><cfelse><a href="#SubmitAlias#?action=detail&PostNum=#PostNum#&Thread=#Thread#&roomID=#roomID#&entryID=#EntryID#">#title#</a></cfif>
                        (#ThreadCount#)
                        </td>
                        <td height=13 valign=middle>#DefaultFont##Author#&nbsp;</td>
                        <td height=13 valign=middle>#DefaultFont##DateFormat(CreateDate,'m/d/yy')#, #Hour(createDate)#:#Minute(createDate)#:#Second(createDate)#</td>
                        </tr>
                        <cfset printlist=listappend(printlist, list.entryID)>
                  </cfoutput>
            </cfif>
            <cfquery name="list2" datasource="#Dbname#" maxRows="1">
                  select PostNum, Thread, Author, CreateDate, Title, EntryID, ThreadCount, ThreadEnd, ReplyTo
                  from connectMessages
                  where replyTo=#listgetat(stack,listlen(stack))# and entryID not in (#doneList#)
                  ORDER BY PostNum desc, Thread Asc;
            </cfquery>
            
            
            <cfif list2.recordcount is not 0>
                  <cfset stack=listappend(stack,list2.entryID)>
                  <cfset donelist=listappend(donelist,list2.entryID)>
                  <cfset indent=indent+1>
            <cfelse>
                  <cfset stack=listdeleteat(stack,listlen(stack))>
                  <cfset indent=indent-1>
            </cfif>
            <cfif listlen(stack) is not 0>
            <cfif not listcontains(printlist,listgetat(stack,listlen(stack)))>
            <cfoutput query="list2">
                   <cfset count=count+1>
                    <tr <cfif #count# MOD 2 eq 1>bgcolor="white"<CFELSE>bgcolor="#RowColor#"</cfif>>
                              <td height="13" valign="MIDDLE" nowrap>
                              <cfloop from="2" to="#indent#" index="v">
                                    <cfset incnt=indent-(v-2)>
                                    <cfquery name="check" datasource="#dbname#">
                                          select entryID from connectMessages
                                          where replyTo=#listGetAt(stack,listlen(stack)-incnt)# and entryID not in (#printlist#)
                                          ORDER BY PostNum desc, Thread Asc;
                                    </cfquery>
                                    <cfif check.recordCount is 1>
                                          <img src="images/i.gif" align="TOP" width=20 height=20 border=0>      
                                    <!----cfelseif v gt indent and listlen(stack) gt 1>
                                          <img src="#ImagePath#t.gif" align="TOP" width=20 height=20 border=0---->      
                                    <cfelseif check.recordcount gt 1>
                                          <img src="images/i.gif" align="TOP" width=20 height=20 border=0>                                          
                                    <cfelse>
                                          <img src="images/spacer.gif" align="TOP" width=20 height=20 border=0>
                                    </cfif>
                              </cfloop>
                              <cfquery name="check" datasource="#dbname#">
                                          select entryID from connectMessages
                                          where replyTo=#listGetAt(stack,listlen(stack)-1)#
                                          and entryID not in (#donelist#) and entryID not in (#entryID#)                              
                                          ORDER BY PostNum desc, Thread Asc;
                              </cfquery>
                              <cfif check.recordcount is 0>
                                    <img src="images/l.gif" align="TOP" width=20 height=20 border=0>
                              <cfelse>
                                    <img src="images/t.gif" align="TOP" width=20 height=20 border=0>
                                    <!----img src="#ImagePath##IIF(ThreadEnd,DE('l.gif'),DE('t.gif'))#" align="TOP" width=20 height=20 border=0----->
                              </cfif>
                              
                              #DefaultFont#<cfif EntryID eq Url.EntryID><b>#Title#</b><cfelse><a href="#SubmitAlias#?action=detail&PostNum=#PostNum#&Thread=#Thread#&roomID=#roomID#&entryID=#EntryID#">#title#</a></cfif>
                        </td>
                        <td>#DefaultFont##list2.Author#&nbsp;</td>
                        <td>#DefaultFont##DateFormat(list2.CreateDate,'m/d/yy')#</td>
                        </tr>
                  <cfset printlist=listappend(printlist,list2.entryID)>      
            </cfoutput>
            
            </cfif>
            </cfif>
            
      </cfloop>




0
 
substandCommented:
also, you can just look at the javascript source on that page you mentioned to see how to implement the javascript.
0
 
ts20031Author Commented:
did u click on navigate top the like i send you click on that u able too see the trees
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
substandCommented:
no, but i thought thepage you posted would have it.  I ended up finding what i thought you meant when i clicked on the form button that said "navigate from tree top"....

in any case, what I said and assumed is still correct.

so try it.
0
 
ts20031Author Commented:
thanks for replay but how can u collepase and expand the tree . thanks
0
 
ts20031Author Commented:
can you show me your link also. . thanks
0
 
ts20031Author Commented:
can you show me your link also. . thanks
0
 
substandCommented:
you'll have to collapse and expand it using javascript. basically putting things in divs and then changing the div style='visibility: hidden/showing'

otherwise, if you want it like that page you linked to, then they just reload the page.

so you could say make the link go back to the same page with an url variable ?show=#id#

then put the code to expand the show id using CF if you don't want to deal with javascript.



0
 
ts20031Author Commented:
can u give me a code for both like div tag and page u link.
thnks. really appreciated your help..
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now