?
Solved

tree question --challenge

Posted on 2003-03-09
9
Medium Priority
?
232 Views
Last Modified: 2013-12-24
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
Comment
Question by:ts20031
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 10

Accepted Solution

by:
substand earned 200 total points
ID: 8106742
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
 
LVL 10

Expert Comment

by:substand
ID: 8106748
also, you can just look at the javascript source on that page you mentioned to see how to implement the javascript.
0
 

Author Comment

by:ts20031
ID: 8107869
did u click on navigate top the like i send you click on that u able too see the trees
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 10

Expert Comment

by:substand
ID: 8107936
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
 

Author Comment

by:ts20031
ID: 8108083
thanks for replay but how can u collepase and expand the tree . thanks
0
 

Author Comment

by:ts20031
ID: 8108091
can you show me your link also. . thanks
0
 

Author Comment

by:ts20031
ID: 8108095
can you show me your link also. . thanks
0
 
LVL 10

Expert Comment

by:substand
ID: 8113199
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
 

Author Comment

by:ts20031
ID: 8118711
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question