I have a query that returns hundres of records and a field called [query].currentrow. This works great as it displays the row number for the entire recordset from 1 to xxx.
However, my customer would like this number to reset when a specific field changes. How does one do that? I am putting some sample code in for claification:
I can’t help but think that there’s a better way to reset that counter variable since you have the groupby parameter in the cfoutput…*but I can’t think of anything right now.
Well with cfoutput group, it’s a little simpler. But not by much. You create a counter variable and use it instead of currentRow. Reset #counter# to 1 inside the outer <cfoutput> and increment it by 1 inside the inner <cfoutput>.
It’s 1 variable instead of 2. But not a massive improvement imo Too bad there’s no “grouped” currentRow variable or something.
You’re going to have to use cfoutput with the groupby parameter instead of cflooping through your list. Also, instead of using currentRow you’re going to have to create two variables, one that does the counting for you and then one that holds the value of the field that will be changing. Then in your loop test the previous column value (‘holder variable’) with the current column value (query column) and if they don’t match, then reset the counter variable, else add one to it and output.
I can’t help but think that there’s a better way to reset that counter variable since you have the groupby parameter in the cfoutput…*but I can’t think of anything right now.