943,670 Members | Top Members by Rank

Ad:
  • ColdFusion Discussion Thread
  • Marked Solved
  • Views: 1559
  • ColdFusion RSS
Jun 17th, 2009
0

Grab data from alternate rows

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 2
Light Poster
cheapterp is offline Offline
33 posts
since Jun 2008
Jun 18th, 2009
0

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.
Last edited by freshfitz; Jun 18th, 2009 at 9:16 am.
Reputation Points: 12
Solved Threads: 36
Posting Pro in Training
freshfitz is offline Offline
436 posts
since Sep 2008
Jun 18th, 2009
0

Re: Grab data from alternate rows

Click to Expand / Collapse  Quote originally posted by freshfitz ...
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
Reputation Points: 10
Solved Threads: 2
Light Poster
cheapterp is offline Offline
33 posts
since Jun 2008
Jun 18th, 2009
1

Re: Grab data from alternate rows

If there is only 2 rows this should work

ColdFusion Syntax (Toggle Plain Text)
  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.
Reputation Points: 12
Solved Threads: 36
Posting Pro in Training
freshfitz is offline Offline
436 posts
since Sep 2008
Jul 23rd, 2009
1

Re: Grab data from alternate rows

Click to Expand / Collapse  Quote originally posted by cheapterp ...
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:

coldfusion Syntax (Toggle Plain Text)
  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.
Reputation Points: 12
Solved Threads: 1
Newbie Poster
macslayer is offline Offline
11 posts
since Mar 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ColdFusion Forum Timeline: Is it possible to install a Wordpress blog as part an existing coldfusion website?
Next Thread in ColdFusion Forum Timeline: Data Mining Coldfusion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC