Query of Queries

Discussion in 'Programming' started by donboers, Feb 20, 2012.

  1. #1
    I have a problem with a where clause in some Query of Queries. I'm working on a site where there are several menus spread over the page I thought the best way to that would be to grab all menu items from the database with a main query and use several Query of Queries to get the different menus needed. But somehow that isn't working. Below you'l se the main query and one of the Query of Queries to get one of the menus. Note I'm using this in a Coldfusion component:
    
      <cffunction name="getMenus" access="public" returntype="query">
        <cfset var getMenus = ""/>
        	<cfquery name="getMenus" datasource="#Application.dsn#">
          	SELECT
            			P.page_id
                ,	P.page_sequence
            		,	P.page_address
                ,	C.menu_title
                ,	C.language_abbr
            FROM
            			pages P
            LEFT 
            	JOIN	content C
              	ON	P.page_id = C.page_id
            WHERE
            				C.language_abbr = <cfqueryparam cfsqltype="cf_sql_char" value="#Trim( Session.language )#" /> 
            ORDER
            		BY	P.page_sequence           
          </cfquery>
    		<cfreturn getMenus>    
    	</cffunction>
      
    	<cffunction name="getMainmenu" access="public" returntype="query">
    		<cfargument name="q" required="Yes" type="query">  
    		<cfset var getMenu = "">
        	<cfquery name="getMenu" dbtype="query">
    				SELECT 
            			*
    				FROM 	arguments.q
    				WHERE 
            			P.page_id BETWEEN <cfqueryparam cfsqltype="cf_sql_idstamp" value="#Val( 1 )#" >
                  						AND	<cfqueryparam cfsqltype="cf_sql_idstamp" value="#Val( 8 )#" >						      
          </cfquery>
    		<cfreturn getMenu>		  
      </cffunction> 
    
    Code (markup):
    and the call:
    
    <cfscript> 
    	siteCFC			= createObject("component", "components.cfcSite");
    	getMenus			= siteCFC.getMenus();	
    	getMainmenu		= siteCFC.getMainmenu(getMenus);
    
    </cfscript>
    
    Code (markup):
    As you can see do I use the argument q to define the other function, but no matter what I try I gives me all menu items (24) instead of the 8 as in the where clause. Does anyone see what i'm doing wrong? Thank you in advance.
     
    donboers, Feb 20, 2012 IP