Grab data from alternate rows

Thread Solved

Join Date: Jun 2008
Posts: 28
Reputation: cheapterp is an unknown quantity at this point 
Solved Threads: 2
cheapterp's Avatar
cheapterp cheapterp is offline Offline
Light Poster

Grab data from alternate rows

 
0
  #1
Jun 17th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 337
Reputation: freshfitz is an unknown quantity at this point 
Solved Threads: 27
freshfitz freshfitz is offline Offline
Posting Whiz

Re: Grab data from alternate rows

 
0
  #2
Jun 18th, 2009
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.
Last edited by freshfitz; Jun 18th, 2009 at 9:16 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 28
Reputation: cheapterp is an unknown quantity at this point 
Solved Threads: 2
cheapterp's Avatar
cheapterp cheapterp is offline Offline
Light Poster

Re: Grab data from alternate rows

 
0
  #3
Jun 18th, 2009
Originally Posted by freshfitz View Post
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 337
Reputation: freshfitz is an unknown quantity at this point 
Solved Threads: 27
freshfitz freshfitz is offline Offline
Posting Whiz

Re: Grab data from alternate rows

 
1
  #4
Jun 18th, 2009
If there is only 2 rows this should work

  1. <cfquery name="Query1" datasource="#application.dsn#">
  2. select column 3 // replace with name of column 3
  3. from TableName // replace with the table name in the data base
  4. where tableName.Column 3 = 'The vAlue in the database that is at row1 colum3 keep i inside these quotes'
  5.  
  6. </cfquery>
  7.  
  8. <cfquery name="Query2" datasource="#application.dsn#">
  9. select column 4 // replace with name of column 4
  10. from TableName // replace with the table name in the data base
  11. where tableName.Column 4 = 'the value data in of Row2 Column4'
  12. </cfquery>
  13.  
  14. <cfoutput>
  15. <tr>
  16.  
  17. <td width="10"><div class="content_black">#Query1.Column3#&nbsp;</div></td>
  18. <td width="10"><div class="content_black">#Query2.Column4#&nbsp;</div></td>
  19.  
  20. </tr>
  21. </cfoutput>
Last edited by freshfitz; Jun 18th, 2009 at 9:15 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: macslayer is an unknown quantity at this point 
Solved Threads: 1
macslayer macslayer is offline Offline
Newbie Poster

Re: Grab data from alternate rows

 
1
  #5
Jul 23rd, 2009
Originally Posted by cheapterp View Post
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:

  1. <cfquery name="blah" datasource="#dsn3">
  2. select * from table
  3. </cfquery>
  4.  
  5. <cfoutput>
  6. <cfloop query="blah">
  7. row:#CurrentRow# mod2:#CurrentRow MOD 2#<br>
  8. <cfloop>
  9. </cfoutput>
Last edited by peter_budo; Jul 24th, 2009 at 2:29 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC