<HTML>
<HEAD><TITLE>Seeing The Forest For The Trees</TITLE></HEAD>
<BODY>

<!--- Get list of ratings from database --->
<CFQUERY NAME="GetRatings" DATASOURCE="ows">
  SELECT RatingID, Rating
  FROM FilmsRatings
  ORDER BY Rating
</CFQUERY>

<!--- Get information about films from database --->
<CFQUERY NAME="GetFilms" DATASOURCE="ows">
  SELECT FilmID, MovieTitle, RatingID
  FROM Films
  ORDER BY MovieTitle
</CFQUERY>

<!--- Fetch a listing of current actors from the database --->
<CFQUERY NAME="GetActors" DATASOURCE="ows">
  SELECT ActorID, NameFirst, NameLast, Gender
  FROM Actors
  ORDER BY NameLast, NameFirst
</CFQUERY>


<!--- Tree controls must appear between <CFFORM> tags --->
<CFFORM ACTION="#CGI.SCRIPT_NAME#" METHOD="POST">

  <!--- Tree control --->
  <CFTREE
    NAME="NavTree"
    WIDTH="300"
    HEIGHT="400"
    BORDER="Yes"
    APPENDKEY="No">

    <!--- Root tree item --->  
    <CFTREEITEM VALUE="root" DISPLAY="Orange Whip Studios" EXPAND="Yes">
    <!--- Tree item for films --->  
    <CFTREEITEM PARENT="root" VALUE="Films" DISPLAY="Films" EXPAND="No">
    <!--- Tree item for actors --->  
    <CFTREEITEM PARENT="root" VALUE="Cast" DISPLAY="Cast Members" EXPAND="Yes">
    <!--- Tree item for actors --->  
    <CFTREEITEM PARENT="Cast" VALUE="CastFemale" DISPLAY="Actresses" EXPAND="No">
    <!--- Tree item for actors --->  
    <CFTREEITEM PARENT="Cast" VALUE="CastMale" DISPLAY="Actors" EXPAND="No">
        
    <!--- For each rating, generate a tree item --->
    <!--- Specify Films as its parent, so it appears within films visually --->
    <CFLOOP QUERY="GetRatings">
      <CFTREEITEM
        PARENT="Films" 
        VALUE="Rating #RatingID#"
        DISPLAY="#Rating#">
    </CFLOOP>
    
    
    <!--- For each film, generate a tree item --->
    <CFLOOP QUERY="GetFilms">
      <!--- Film should appear in tree according to its rating --->
      <CFSET ParentItem = "Rating #GetFilms.RatingID#">
    
      <!--- Generate actual tree item --->
      <CFTREEITEM
        PARENT="#ParentItem#" 
        VALUE="#FilmID#"
        DISPLAY="#MovieTitle#"
        HREF="ShowFilm.cfm?FilmID=#FilmID#">
    </CFLOOP>

    
    <!--- Tree item for each actor --->  
    <CFLOOP QUERY="GetActors">
      <!--- Place under Actors or Actresses as appropriate --->
      <CFIF GetActors.Gender EQ "F">
        <CFSET ParentItem = "CastFemale">
      <CFELSE>  
        <CFSET ParentItem = "CastMale">
      </CFIF>
    
      <!--- Generate actual tree item --->
      <CFTREEITEM 
        PARENT="#ParentItem#"
        VALUE="#ActorID#"
        DISPLAY="#NameFirst# #NameLast#"
        EXPAND="No"
        HREF="ShowActor.cfm?ActorID=#ActorID#">
    </CFLOOP>

  </CFTREE>
</CFFORM>  

</BODY>
</HTML>