querie errors when calling function from inside itself

Discussion in 'Programming' started by kevinric7, Jul 2, 2009.

  1. #1
    Excuse my ignorance. I have only been working with CFML for a few days now. I'm trying to generate a webpage dynamically, and don't want all the freedom that a WYSIWUG editor gives.

    <cffunction name="buildPage" access="public" returntype="string">
      <cfargument name="page" type="numeric" required="yes">
      <cfargument name="parent" type="numeric" required="yes">
      <cfquery name="getContentList" datasource="flight_db">
      SELECT contentID, type FROM content WHERE pageID = #page# AND parentID = #parent# ORDER BY orderID
      </cfquery>
      <cfloop query="getContentList">
        <cfswitch expression="#getContentList.type#">
        <cfcase value="1">
    ...
        </cfcase>
        <cfcase value="2">
    ...
        </cfcase> 
        <cfcase value="3">
    ...
        </cfcase>
    ...
    ...
        <cfcase value="5">
          <ul>
          <cfoutput>#buildPage(page=page, parent=getContentList.contentID)#</cfoutput>
          </ul>
        </cfcase>
        <cfcase value="6">
          <ol>
          <cfoutput>#buildPage(page=page, parent=getContentList.contentID)#</cfoutput>
          </ol>
        </cfcase>
        <cfcase value="7">
          <cfquery name="getContent" datasource="flight_db" maxrows="1">
          SELECT txt FROM list_items WHERE contentID = #getContentList.contentID#
          </cfquery>
          <cfoutput query="getContent"><li>#getContent.txt# --- #getContentList.contentID#</li></cfoutput>
        </cfcase>
        </cfswitch>
      </cfloop>
    </cffunction>
    ...
    ...
    <cfoutput>#buildPage(page=pageID, parent=0)#</cfoutput>
    
    Code (markup):
    When it comes time to call the function from inside itself (like when creating ULs or OLs, the query seems to be replaced with the innermost version, and keeps duplicating the results.
    Output:
    •News 1 --- 5
    •News 2 --- 6
    1.Number One --- 8
    •Number One --- 8
    Number One --- 8

    It's like calling two different queries (one looping inside another). How can i fix this? Thanks.
     
    kevinric7, Jul 2, 2009 IP
  2. kevinric7

    kevinric7 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    nevermind, i figured it out
     
    kevinric7, Jul 2, 2009 IP