1 Replies - 5303 Views - Last Post: 07 December 2009 - 06:33 AM Rate Topic: -----

#1 gebuh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-July 08

cf7 call cfc function after select from dropdown

Post icon  Posted 05 December 2009 - 08:08 AM

Hi, I'm a CF noob, can't figure this one out. I'm running MX7, I have a dropdown list that's populated from a mysql query.
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"
					<option value="-1"></option>
				<!--- 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#">

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" 
			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#'

	<cfreturn table_name />

	<!--- 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" 
			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
	<cfreturn query_table />

  * 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" 
			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="">
	<cfswitch expression="#functional_area#">
		<cfcase value="Hardware" delimiters=";">
			<cfset page_name="hardware.cfm">
		<cfcase value="Logistics" delimiters=";">
			<cfset page_name="logistics.cfm">
		<cfcase value="Program" delimiters=";">
			<cfset page_name="program.cfm">
		<cfcase value="Software" delimiters=";">
			<cfset page_name="software.cfm">
		<cfcase value="System" delimiters=";">
			<cfset page_name="system.cfm">
			<cfset page_name="error.cfm">
	<cfreturn page_name />


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

Is This A Good Question/Topic? 0
  • +

Replies To: cf7 call cfc function after select from dropdown

#2 poncho4all   User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,422
  • Joined: 15-July 09

Re: cf7 call cfc function after select from dropdown

Posted 07 December 2009 - 06:33 AM

Shouldnt this be
WHERE fk_sub_function_id = '#sub_func_id#'

WHERE fk_sub_function_id in (#sub_func_id#)

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1