-
ColdFusion (
http://www.daniweb.com/forums/forum19.html)
| cheapterp | Jun 17th, 2009 12:40 pm | |
| 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? |
| freshfitz | Jun 18th, 2009 9:15 am | |
| Re: Grab data from alternate 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. |
| cheapterp | Jun 18th, 2009 1:03 pm | |
| Re: Grab data from alternate rows Quote: Originally Posted by freshfitz (Post 893730) 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 |
| freshfitz | Jun 18th, 2009 9:09 pm | |
| Re: Grab data from alternate rows 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# </div></td>
<td width="10"><div class="content_black">#Query2.Column4# </div></td>
</tr>
</cfoutput> |
| macslayer | Jul 23rd, 2009 3:20 pm | |
| Re: Grab data from alternate rows Quote: Originally Posted by cheapterp (Post 893930) 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> |
| All times are GMT -4. The time now is 9:49 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC