Ask a Question related to Coldfusion Database Access, Design and Development.
-
walkeraj00 #1
Variable in database query?
Here is a function I am attempting to use in a web application I'm
developining. Basically, I am attempting to create a function to generate a
<select> variable in a form. I want the select variable's default option to be
based upon the value that's already in the database. So, for instance, if the
selectbox is for value F_E1, and the value in the database is "YES", then I
want "yes" to be pre-selected in the form. What I wanted to do was pass a
string that said something like "F_E1" to the function, which would then
generate a form entry based on the database value of query.F_E1.
The error I'm getting is as follows: The variable RubaReports. ends with a "."
character. You must supply an additional structure key or delete the "."
character.
Any ideas?
<cffunction name="gen_select">
<cfargument name="field_name" type="string" required="yes">
<cfoutput query="RubaReports">
<cfif RubaReports.#field_name# IS "N/A" OR RubaReports.#field_name# IS "">
<select name="#field_name#">
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="N/A" selected>N/A</option>
</select>
<cfelse>
<select name="#field_name#">
<option value="Yes"<cfif RubaReports.#field_name# IS "Yes">
selected</cfif>>Yes</option>
<option value="No"<cfif RubaReports.#field_name# IS "No">
selected</cfif>>No</option>
<option value="N/A">N/A</option>
</select>
</cfif>
</cfoutput>
</cffunction>
walkeraj00 Guest
-
PARSING A QUERY OF QUERY WITH A VARIABLE VALUE
On my first page the user selects a project. I am using the variable SelectedProject: <cfset SelectedProject =... -
Using a Variable to create the SQL Query
I need to create a "dynamic" Update query. I want to store the meet of the command in a variable and then reference the variable in in query. ... -
Using variable in sql query
Hello again, I'm trying to run an sql query using a string as in the following: <cfset string = "address1=' #evaluate("form.param#count#")# ',... -
Help with variable query?
I'm having an arbitrary query input by the user, then to make that query into an excel file it must be put into a table similar to below. Since I... -
Embedding a variable in an SQL Query
I am getting the following error when running : $result = mysql_query("SELECT * FROM users WHERE Username = $ThisUsername"); $num_rows =... -
Dan Bracuk #2
Re: Variable in database query?
First, you have to scope your field_name variable. The scope is arguments.
I know you have to change RubaReports.#field_name# to something else, but I
forget what. Perhaps, something like this.
RubaReports["#field_name#"]
or something else
Dan Bracuk Guest
-
walkeraj00 #3
Re: Variable in database query?
Yes, of course! That is the correct syntax, I believe, but now I am getting
the following error:
Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result
as a simple value, however, the result cannot be converted to a simple value.
Simple values are strings, numbers, boolean values, and date/time values.
Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you are trying to use a complex
value as a simple one. For example, you might be trying to use a query variable
in a <CFIF> tag. This was possible in ColdFusion 2.0 but creates an error in
later versions.
The error occurred in /oradced/webpages/dca/ruba/report/Ruba_Detail.cfm: line
19
17 : <cfargument name="field_name" type="string" required="yes">
18 : <cfoutput query="RubaReports">
19 : <cfif RubaReports["#field_name#"] IS "N/A" OR
RubaReports["#field_name#"] IS "">
20 : <select name="#field_name#">
21 : <option value="Yes">Yes</option>
Well, that's exactly right! I'm trying to use a query inside of a <cfif> tag!
What's the solution to this? An intermediate variable?
walkeraj00 Guest
-
-
walkeraj00 #5
Re: Variable in database query?
Here's the working code. I eliminated the last error by simply making an
intermediate variable. Dan, it was unnecessary to specifically scope the
argument. I just wasn't using it right.
<cffunction name="gen_select">
<cfargument name="field_name" type="string" required="yes">
<cfoutput query="RubaReports">
<cfset fieldresult=RubaReports["#field_name#"]>
<cfif fieldresult IS "N/A" OR fieldresult IS "">
<select name="#field_name#">
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="N/A" selected>N/A</option>
</select>
<cfelse>
<select name="#field_name#">
<option value="Yes"<cfif fieldresult IS "Yes"> selected</cfif>>Yes</option>
<option value="No"<cfif fieldresult IS "No"> selected</cfif>>No</option>
<option value="N/A">N/A</option>
</select>
</cfif>
</cfoutput>
</cffunction>
walkeraj00 Guest



Reply With Quote

