954,160 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Grab data from alternate rows

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?

cheapterp
Light Poster
33 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
 

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.

freshfitz
Posting Pro in Training
436 posts since Sep 2008
Reputation Points: 12
Solved Threads: 36
 

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

cheapterp
Light Poster
33 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
 

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>
freshfitz
Posting Pro in Training
436 posts since Sep 2008
Reputation Points: 12
Solved Threads: 36
 

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#
<cfloop>
</cfoutput>
macslayer
Newbie Poster
11 posts since Mar 2008
Reputation Points: 12
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You