Is there a way to grab data from alternate records in a ColdFusion query?
Essentially, what I am trying to do is this:
I am querying my database to grab some data. 2 rows of data are returned here.
Now I want to set 2 variables - var1 = row1.columnA
and var2 = row2.columnX

How do I do this?

I'm kinda confused so you have a table column 1 column 2 column 3, row 1 row 2 row 3 row 4 row 5 and you want var1 to show row 1,3 and 5 and var2 to show row 2,4 and 6 ?

You can set the sql statement so var1 shows columnA and var2 shows ColumnX but not sure if you can skip rows.

I'm kinda confused so you have a table column 1 column 2 column 3, row 1 row 2 row 3 row 4 row 5 and you want var1 to show row 1,3 and 5 and var2 to show row 2,4 and 6 ?

You can set the sql statement so var1 shows columnA and var2 shows ColumnX but not sure if you can skip rows.

Actually, there are only 2 rows. So like the following:
Table:
Column 1, Column 2, Column 3, Column 4
Row 1
Row 2

What I want now is:
var 1 = Row1.Column3
var 2 = Row2.Column4

If there is only 2 rows this should work

<cfquery name="Query1" datasource="#application.dsn#">
	select column 3 // replace with name of column 3
	from TableName      // replace with the table name in the data base
	where tableName.Column 3 = 'The vAlue in the database that is at row1 colum3 keep i inside these quotes'
	
	</cfquery>

<cfquery name="Query2" datasource="#application.dsn#">
	select column 4 // replace with name of column 4
	from TableName      // replace with the table name in the data base
	where tableName.Column 4 = 'the value data in of Row2 Column4'
	</cfquery>

<cfoutput>
<tr>
	
	<td width="10"><div class="content_black">#Query1.Column3#&nbsp;</div></td>
	<td width="10"><div class="content_black">#Query2.Column4#&nbsp;</div></td>
	
 </tr>
</cfoutput>

Actually, there are only 2 rows. So like the following:
Table:
Column 1, Column 2, Column 3, Column 4
Row 1
Row 2

What I want now is:
var 1 = Row1.Column3
var 2 = Row2.Column4

I would test on MOD 2 of currentrow:

<cfquery name="blah" datasource="#dsn3">
select * from table
</cfquery>

<cfoutput>
<cfloop query="blah">
   row:#CurrentRow# mod2:#CurrentRow MOD 2#<br>
<cfloop>
</cfoutput>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.