Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Variables 1

Status
Not open for further replies.

Renoyl

Technical User
Mar 15, 2001
11
US
I have the following basic query. The #form.funddate# gets the value of the radio button or buttons picked by the user from the form page its on. I then take that variable in this query on the action page:
<CFQUERY NAME=&quot;FundSearch&quot;
DATASOURCE=&quot;IMGWEB&quot;>
SELECT FundName, '#Form.date#'
FROM FRTCPERF


WHERE FundName LIKE '#Form.FundName#%'


</cfquery>


My problem is that when I CFOUTPUT this query result with #form.funddate# I get the Value of the radio button, and not the data from the database. The #form.funddate# should just be representing the column name of my database in the radio buttons value, not itself.




 
Scoping your variables is extremely important, especially when you're just beginning to learn CF.

You're saying that:
<CFOUTPUT query=&quot;fundSearch&quot;>
#form.funddate#
</CFOUTPUT>

returns the radio button value? That's because thats the variable you're specifying. To see what the query returned, you need to specify the query variable.

<CFOUTPUT query=&quot;fundSearch&quot;>
#fundSearch.fundname#
</CFOUTPUT>

My guess is you'll spend more time fixing your query that fixing its output.
 
Thanks for the response! I have been able to get the #FundSearch.fundname# with CFOUTPUT, but not the #form.date# output. The #form.date# is supposed to be representing a column in the database that the user has picked. I want then to call that column that the user picked in the form with a checkbox in the CFOUTPUT tag in the action page. I just need to pass that variable so it is treated like one of the database columns(LatestMonth, OneYear, TwoYears)Does that explain it better?

Here is the form page:
<FORM ACTION=&quot;fund_search2.cfm&quot; METHOD=&quot;post&quot;>
Parent Folder Name: <input type=&quot;Text&quot; name=&quot;FundName&quot; required=&quot;Yes&quot; size=&quot;25&quot;>
<br>
<INPUT TYPE = &quot;checkbox&quot; Name=&quot;date&quot; Value=&quot;LatestMonth&quot;>Latest Month</INPUT>
<INPUT TYPE = &quot;checkbox&quot; Name=&quot;date&quot; Value=&quot;OneYear&quot;>One Year</INPUT>
<INPUT TYPE = &quot;checkbox&quot; Name=&quot;date&quot; Value=&quot;TwoYears&quot;>Two Years</INPUT>

<INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Search&quot;>
</FORM>

Here is the action page with the output after:
<CFQUERY NAME=&quot;FundSearch&quot;
DATASOURCE=&quot;IMGWEB&quot;>
SELECT FundName, #Form.date#
FROM FRTCPERF
WHERE FundName LIKE '#Form.FundName#%'

</cfquery>
<CFOUTPUT QUERY =&quot;FundSearch&quot;>
<tr>
<td height=&quot;38&quot; width=&quot;214&quot; valign=&quot;top&quot;>#FundSearch.FundName#</td>

<td height=&quot;38&quot; width=&quot;214&quot; valign=&quot;top&quot;>#Form.date#</td>
</tr>
</CFOUTPUT>
 
It is much more clear now that I see the code. Your fix is to use AS in your SQL.

First, the form page:
Change your type=&quot;checkbox&quot; to type=&quot;radio&quot;
<!--- form page --->

<FORM ACTION=&quot;fund_search2.cfm&quot; METHOD=&quot;post&quot;>
Parent Folder Name: <input type=&quot;Text&quot; name=&quot;FundName&quot; required=&quot;Yes&quot; size=&quot;25&quot;>
<br>
<INPUT TYPE = &quot;radio&quot; Name=&quot;date&quot; Value=&quot;LatestMonth&quot;>Latest Month</INPUT>
<INPUT TYPE = &quot;radio&quot; Name=&quot;date&quot; Value=&quot;OneYear&quot;>One Year</INPUT>
<INPUT TYPE = &quot;radio&quot; Name=&quot;date&quot; Value=&quot;TwoYears&quot;>Two Years</INPUT>

<INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Search&quot;>
</FORM>

Next, your action page:
Use the SQL article 'AS' to define how CF will access the field. Since the name of the field will vary, you use AS so that CF can access a constant.

<!--- form action --->
<CFQUERY NAME=&quot;FundSearch&quot;
DATASOURCE=&quot;IMGWEB&quot;>
SELECT FundName, #Form.date# as theDate
FROM FRTCPERF
WHERE FundName LIKE '#Form.FundName#%'

</cfquery>
<CFOUTPUT QUERY =&quot;FundSearch&quot;>
<tr>
<td height=&quot;38&quot; width=&quot;214&quot; valign=&quot;top&quot;>#FundSearch.FundName#</td>

<td height=&quot;38&quot; width=&quot;214&quot; valign=&quot;top&quot;>#FundSearch.theDate#</td>
</tr>
</CFOUTPUT>

Please click 'let strantheman know..' link below to throw a vote my way. thanks
 
Thanks so much! I ahve been trying to figure it out for 2 days now. I did not know about changing the variables name to be able to reference it like that. Why does ColdFusion not let that variable pass?
 
Please cast a vote for me Renoyl.

Variables can only have one definition. In your case, you had a #date# variable. Its value was either 'lastmonth' 'oneyear' or 'twoyears'

You used that variable to determine the name of a field in your query. The value of #date# didn't change just because you ran a query. Its still 'lastmonth' instead of a date.

There is one other method you can try, that's the evaluate() function. This function outputs the value of a variable, if there's a variable that = 'lastmonth'.

#evaluate(date)# might return your date, instead of the string 'lastmonth' .. although the SQL method is much more sound.
 
I have no &quot;let Stantheman know&quot; button. Do you have to be a member. I need to join now anyway so I will cast you a vote
. This was a tremendous help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top