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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query using CF variables 1

Status
Not open for further replies.

calista

Programmer
Joined
Jan 24, 2001
Messages
545
Location
US
Here's the challenge: I am creating an application that takes an input from a form, and based on the value the user selected, that determines which table to query against. How do I get the results of the query out?
This is my query:
Code:
<CFQUERY NAME=&quot;GetAddress&quot;
					DATASOURCE=&quot;#Application.Datasource#&quot;
					DBTYPE=&quot;ODBC&quot;>
						SELECT	#AdrID#,#AdrAddress#
						FROM	#AdrTable#
				</CFQUERY>
AdrTable is set based on user input. As you can see, AdrID and AdrAddress are columns in the table. I am trying to output the results of the query as follows:
Code:
<CFOUTPUT QUERY=&quot;GetAddress&quot;>
					<TABLE ALIGN=&quot;center&quot; BORDER=&quot;1&quot;>
					<TR>
						<TD WIDTH=&quot;25&quot;>#AdrID#</TD>
						<TD WIDTH=&quot;100&quot;>#AdrAddress#</TD>
					</TR>
					</TABLE>
				</CFOUTPUT>
It displays the column names for each element in the table. On one level, I understand that, because they are variables I set earlier, and it is displaying the variable value. But, how do I get it to give me the query results? Or, if there's a better way, I'm open to suggestion. Thanks, everyone! Calista :-X
Jedi Knight,
Champion of the Force
 
You could do it this way:

<CFQUERY NAME=&quot;GetAddress&quot;
DATASOURCE=&quot;#Application.Datasource#&quot;
DBTYPE=&quot;ODBC&quot;>

SELECT #FORM.AdrID#,#FORM.AdrAddress#
FROM #FORM.AdrTable#
</CFQUERY>


<CFOUTPUT QUERY=&quot;GetAddress&quot;>
[COLOR=008080]<TABLE ALIGN=&quot;center&quot; BORDER=&quot;1&quot;>[/color]
[COLOR=008080]<TR>[/color]
[COLOR=008080]<TD WIDTH=&quot;25&quot;>[/color]#Evaluate(FORM.AdrID)#[COLOR=008080]</TD>[/color]
[COLOR=008080]<TD WIDTH=&quot;100&quot;>[/color]#Evaluate(FORM.AdrAddress)#[COLOR=008080]</TD>[/color]
[COLOR=008080]</TR>[/color]
[COLOR=008080]</TABLE>[/color]
</CFOUTPUT>

Although, I try to avoid the Evalute() function whenever possible because it really slows the code down. This method is twice as fast as the above method:

<CFOUTPUT QUERY=&quot;GetAddress&quot;>
[COLOR=008080]<TABLE ALIGN=&quot;center&quot; BORDER=&quot;1&quot;>[/color]
[COLOR=008080]<TR>[/color]
[COLOR=008080]<TD WIDTH=&quot;25&quot;>[/color]
#GetAddress
Code:
[
FORM.AdrID
Code:
]
Code:
[
CurrentRow
Code:
]
#
[COLOR=008080]</TD>[/color]
[COLOR=008080]<TD WIDTH=&quot;100&quot;>[/color]
#GetAddress
Code:
[
FORM.AdrAddress
Code:
]
Code:
[
CurrentRow
Code:
]
#
[COLOR=008080]</TD>[/color]
[COLOR=008080]</TR>[/color]
[COLOR=008080]</TABLE>[/color]
</CFOUTPUT> - tleish
 
Thanks, tleish! That did the trick! Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top