Thursday, April 9, 2009

Accessing a queries row by row number

query.column[rownumber]

I was asked to do a task which involved a select box with arrows on each side of it. The arrows were to be used for the next and previous record in the select box when the page first rendered. For awhile I have wanted to use a query row number to access data directly and now get the chance to.

I used the current selected id and loop the query just got the above and below row from the current row by accessing the query struct.

Example:


<cfset the_id="124"/>
<cfset above_id=""/>
<cfset below_id=""/>

<cfloop query="the_query">

<cfif the_id = the_query.id>

<cfset above_id= the_query.id[currentrow + 1] />

<cfset below_id= the_query.id[currentrow - 1] />
<cfbreak />
</cfif>
</cfloop>

No comments:

Post a Comment