Get ID of previous record and Next record during CFoutput of a query

As i output a coldfusion query(multiple records) to the page how can i access the previous record and the next record as the data is written to the page?
Who is Participating?
gdemariaConnect With a Mentor Commented:
If you want to refer back to the previous record or to the next record, you can treat the query's value like a structure..

Assuming your query is MyQuery and you have a field  myField.  This is how you can get the value of the previous record..


and the next record...


Of course, you have to put logic into place to be sure that you're not trying to fetch record zero or not trying to fetch a record beyond the last one..  
erikTsomikSystem Architect, CF programmer Commented:
what you can do is the following
For  example you have a query qryTest
In order to get all records you do qryTest.recordcount, so if you need the record before you qryTest.recordcount -1 and qryTest.recordcount +1
try this approach and let me know if you need more help
ronayersAuthor Commented:
hhh...without testing it that doesnt look like it will work. i thikn that will only add one or subtract one from the record count. shouldnt i be able to do something like qrytest.recordid[i] orsomething like that?
erikTsomikSystem Architect, CF programmer Commented:
check out this tutorila it is similar to what you need
ronayersAuthor Commented:
Thats it! thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.