I have an excel that I read and create a query object using this code
<cfspreadsheet action="read" src="#theFile#" query="qData" headerrow="1" excludeHeaderRow ="true" columns="9,15,51,56,57,58,59" />
So now I have a query object that I output and it outputs in the order that is in the excel.
I loop through it like this
and I get this
Now I need to do the order in reverse like this
Can I sort by a loop? How ?
There are a couple of ways to sort the query object, I believe.
One way would be to loop the object in reverse, if you are strictly going for a reverse-only output.
<cfloop from="#qData.recordcount#" to="1" step="-1" index="idx">
#qData.ID[idx]# #qData.Values[idx]#<br />
If the IDs are always sequential, you can reverse sort like so:
<cfset qDdata.sort(qDdata.findColumn("ID"), FALSE)>
Then output as you normally would. The "FALSE" means DESCENDING; "TRUE" would be ASCENDING.
^ _ ^
Sorry, Wolf. I had some bad info and didn't phrase the question correctly
This is the query object . When it loops the first time it outputs like this
There is NO ID column
Is there a way to sort these via cfloop so that it goes Warner, Simpkins, Moore Smith?
No, because that's not alphabetical or reverse-alphabetical. Is there ANY kind of sequential ID being provided?
If you wanted it sorted alphabetically or reverse-alphabetically, then the Java sort that I suggested could be used on LAST_NAME, or FIRST_NAME, or CITY.
If there are no IDs, then the first option I suggested should work, if you are truly sorting reverse of the information as it was constructed.
^ _ ^
This option should work?
Yup. Basically, you are going through the query backwards, starting at the last record, moving "step -1" (backwards) to the first record. The "idx" is the index based upon where in the iterative loop you are, and the bracket notation is getting the data from that index of the query object.
^ _ ^
Yes, this is the correct answer. As always thank you!
You're welcome, and thank you for marking my answer as correct. I do appreciate it.
^ _ ^