From: kenji776 on
Okay, I have an application that can change frequently, as such, I need to run
a query that tells my main query what it needs to update. So one query provides
the other all the fields it needs to update. The main query and function are
attached. The Insert part works fine, but the values part isn't working. The
output looks like
INSERT INTO moves(name, damage, type, accuracy, recoil, minlevel, price,
Boxing, Wrestling, TaiKwonDo, Karate, Capoeria, SAMBO, Ninjitsu, KungFu, Kempo,
Savate, KickBoxing, MuayThai, description ) VALUES ('Blah', '1', 'Wresting',
'25', '13', '7', '5', '#form.Boxing#', '#form.Wrestling#', '#form.TaiKwonDo#',
'#form.Karate#', '#form.Capoeria#', '#form.SAMBO#', '#form.Ninjitsu#',
'#form.KungFu#', '#form.Kempo#', '#form.Savate#', '#form.KickBoxing#',
'#form.MuayThai#', 'Test')

See how it is just plugging #form.Fightingstylename# instead of actually
finding the value of that field. How can I make it actually find the value of
the field it is creating? I hope this makes sense.


<cffunction name="insertRecord" access="public">
<cfargument name="form" required="yes" type="struct">
<!---<cftry> --->

<cfset dataFile = createObject("component","o_common_queries")>
<cfset fetchStyles = dataFile.FetchStyles()>
<cfquery name="recordQuery" datasource="pitfighter"
username="administrator" password="534Digital980" >
INSERT INTO moves(name,
damage,
type,
accuracy,
recoil,
minlevel,
price,
<cfoutput>
<cfloop query="fetchStyles">
#ReReplace(fetchStyles.name,"[[:space:]]*","","all")#,
</cfloop>
</cfoutput>
description
)

VALUES ('#form.name#',
'#form.damage#',
'#form.move_type#',
'#form.accuracy#',
'#form.recoil#',
'#form.minlevel#',
'#form.price#',
<cfoutput>
<cfloop query="fetchStyles">
<!--- Desired output of this look looks like '#form.boxing#' --->
<cfset prestring = "##form.">
<cfset poststring = "##">
<cfset mainstring = ReReplace(fetchStyles.name,"[[:space:]]*","","all")>
<cfset wholestring = prestring & mainstring & poststring>
'#wholestring#',
</cfloop>
</cfoutput>
'#form.description#')
</cfquery>
<!---<cfcatch type="Any">
<cfoutput>
<p>&nbsp;</p><h2>Error Sites74 - Sorry, There was a file error. Try
re-entering your information</h2>
<input type=button value="Back"
onClick="javascript:window.history.go(-1);" class="buttonstyle">
<cfabort>
</cfoutput>
</cfcatch>
</cftry>--->
</cffunction>

From: kenji776 on
Thanks for the info, I'll check into the evaluate function.
There probably is a better way to do this, but I'm a terrible programmer, so
unless you have any better ideas, i think I'm gonna have to roll with it.

From: Azadi on
see if this works:

<cfloop query="fetchStyles">
<!--- Desired output of this look looks like '#form.boxing#' --->
'#form[ReReplace(fetchStyles.name,"[[:space:]]*","","all")]#',
</cfloop>

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
From: kenji776 on
Thanks for the reply. This was the magic setup that did the trick...

<cfoutput>
<cfloop query="fetchStyles">
<!--- Desired output of this look looks like '#form.boxing#' --->
<cfset prestring = "##form.">
<cfset poststring = "##">
<cfset mainstring =
ReReplace(fetchStyles.name,"[[:space:]]*","","all")>
<cfset wholestring = prestring & mainstring & poststring>
'#evaluate(wholestring)#',
</cfloop>
</cfoutput>

From: Ian Skinner on
Start with the evaulate() function.

Ninety percent of the time this type of logic can be rewritten to make
it simpler and not need this type of double evaluation.