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!

cfquery question

Status
Not open for further replies.

fdgsogc

Vendor
Feb 26, 2004
160
CA
What's wrong with my code here. I am trying to output two different records dynamically. I have two records in a table. I want to use the same query with a dynamic where parameter that is cfset before each query.

If my first record has a value of ONE, and my second record has a value of TWO. The code below is returning the following:

ONE
ONE

When what I am searching for is:

ONE
TWO

I need this ability because these two records are being displayed on the same page but not one under the other so one query will not do. I know I can create two queries here. What I'm trying to achieve though is a standard query that can be managed by parameters.

Code:
<cfset placement = 1>
<cfoutput query="gettext">
#thetext#
</cfoutput>

<br/>

<cfset placement = 2>
<cfoutput query="gettext">
#thetext#
</cfoutput>

So "placement" 1 represents my first record in the database and "placement" 2 represents the second record. Here is the query.
Code:
<cfquery name="gettext" datasource="#db#">
select *
from sitetext
where webpagename = '#webpagename#' and placement = '#placement#'
</cfquery>
 
it's hard to believe that you would use a database table for only two rows, but since you asked "what's wrong with this code" the answer is that you shouldn't query the database twice

just query it once, to return both rows

then, to place the rows onto the page, use

<CFOUTPUT QUERY="queryname" STARTROW="[red]1[/red]" MAXROWS="1">

for the first row, and use

<CFOUTPUT QUERY="queryname" STARTROW="[red]2[/red]" MAXROWS="1">
for the second

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top