How to check the data on the next row while looping through a query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bushnellweb
    New Member
    • Jan 2010
    • 48

    How to check the data on the next row while looping through a query?

    I am looping through a query and I am wondering if there is a way to access data on the next row of the query I am looping through.

    Heres some code:
    Code:
    <cfquery datasource="#ds#" name="myQRY">
       SELECT pic_src FROM pics
       WHERE pic_id = 2
    </cfquery>
    
    <cfoutput query="myQRY">
       <cfif myQRY.row[thisRow + 1].pic_src IS "">
          HELP ME!
       </cfif>
    </cfoutput>
    Soooo... obviously this doesn't work in coldfusion but I was thinking there might be a way to access the next row and the value of a column in that next row, know of anything?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Why would you want to access the next row? When you loop over the query results, it will automatically go to the next row on the next cycle.

    Do you want to access both the current row and the next row in the same cycle?

    Comment

    • NBushnell
      New Member
      • Dec 2010
      • 2

      #3
      To access the next row in a query...
      Code:
       <cfoutput>
          #queryName.field_name[rowNumber]#
       </cfoutput>
      I have had to access the next row before because depending on what the data on the next row was, I had to handle the data on the row I was on. I used to just populate an array with the query data and access it like that but this way eliminates the need for that.

      Comment

      Working...