When the user selects an item from the dropdown I want to call a cfc function which runs a query, to get a table name that will be used in another query.
This is what I have:
<!--- user selects from dropdown --->
<cfselect required="yes" name="sub_function_id" value="sub_function_id" query="sub_function"
display="sub_function" queryPosition="below"
selected="#attributes.sub_function_id#">
<option value="-1"></option>
</cfselect></td>
<!--- if user selected a sub_function, retrieve a table name TODO HANDLE ERROR --->
<cfif isdefined("attributes.sub_function_id")>
<cfinvoke component = "reports.reports_component" method="set_table_name" returnvariable="table_name">
<cfinvokeargument name="sub_func_id" value="1"> <! --- hardcoded value temp for troubleshooting --->
<cfinvokeargument name="attribs" value="#attributes.attribs#">
</cfinvoke>
</cfif>
the cfc:
<cfcomponent displayname="reports_component" hint="functions to output emr reports" output="false"> <!--- * FUNCTION: set_table_name * run query to attrib or characteristic table to get db table name to user in getCharsAttribs * @param sub_func_id : fk_sub_function_id from user selected project type dropdown * @return string : table name for characteristic attribute ---> <cffunction name="set_table_name" access="public" returntype="string" output="false" displayname="set_table_name" hint="set the db table to query from based on user selected fields"> <cfargument name="sub_func_id" type="numeric" required="true"> <cfargument name="attribs" type="string" required="true"> <cfset var table_name =""> <cfquery name="query_attrib_for_table_name" datasource="#application.dsn#" maxrows="1"> SELECT table_name FROM '#attribs#' WHERE fk_sub_function_id = '#sub_func_id#' </cfquery> <cfreturn table_name /> </cffunction> <!--- get all the characteristics and attributes associated with this id ---> <!--- * FUNCTION: getCharsAttribs * for a specified attrib_char_id, return all the attrib/char fields, use table name as variable, this function will be used on different tables * @param attrib_char_id : primary key from specific char attrib table - named by functional area and sub function * @param table_name : table to query data from * @return query : query containing these values ---> <cffunction name="getCharsAttribs" access="public" returntype="query" output="false" displayname="getCharsAttribs" hint="return all chars and attribs for a specified attrib_char_id"> <cfargument name="attrib_char_id" type="int" required="true"> <cfargument name="table_name" type="string" required="true"> <!--- Define variables ---> <cfset var query_table=""> <cfquery name="qry_char_attrib_table" datasource="#application.dsn#"> SELECT * FROM "#table_name#" AS query_table </cfquery> <cfreturn query_table /> </cffunction> <!--- * FUNCTION: getFuncAreaPage * insert description here * @param functional_area : user selected functional area(hardware, sw, system, etc) * @return string : page name for this type of function ---> <cffunction name="getFuncAreaPage" access="public" returntype="string" output="false" displayname="getFuncAreaPage" hint="returns .cfm page based on user selected functional area"> <cfargument name="functional_area" required="true" default="" type="string"> <cfset var page_name=""> <!--- TODO: 12/4/2009 BAD PROGRAMMER, BAD, BAD PROGRAMMER!!! GET RID OF HARD CODED VALUES!!!!! ---> <cfswitch expression="#functional_area#"> <cfcase value="Hardware" delimiters=";"> <cfset page_name="hardware.cfm"> </cfcase> <cfcase value="Logistics" delimiters=";"> <cfset page_name="logistics.cfm"> </cfcase> <cfcase value="Program" delimiters=";"> <cfset page_name="program.cfm"> </cfcase> <cfcase value="Software" delimiters=";"> <cfset page_name="software.cfm"> </cfcase> <cfcase value="System" delimiters=";"> <cfset page_name="system.cfm"> </cfcase> <cfdefaultcase> <cfset page_name="error.cfm"> </cfdefaultcase> </cfswitch> <cfreturn page_name /> </cffunction> </cfcomponent>
when I run this I get this error msg:
Error Executing Database Query.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''attribs' WHERE fk_sub_function_id = '1'' at line 2
the dropdown is not generated, it appears my query is trying to run before the page is even loaded, what am I doing wrong?
thanx in advance

New Topic/Question
Reply




MultiQuote




|