Finding the last row from cfquery

I have

<CFLOOP QUERY="MyInstallments">

<input .......>

bla...

</CFLOOP>

What I need to find is the very last row from the query (already sorted) so that I can apply <cfif>:

<cfif MyInstallments_Last_Row> .... <cfesle> ....</cfif>
JohnLucaniaAsked:
Who is Participating?
 
mkishlineConnect With a Mentor Commented:
You can try either:

<cfloop query="MyInstallments" startrow="#MyInstallments.recordcount#">
  <!--- This will work best if you just want to manipulate or check the content from the last row --->
</cfloop>

or if you need to do something for every row in the query:

<cfloop query="MyInstallments">
  <cfif currentrow EQ MyInstallments.recordcount>
    <!--- Do something if this is the last row of your queryset --->
  <cfelse>
    <!--- Do something else if this isn't the last row --->
  </cfif>
</cfloop>
0
 
siva350Commented:
try something like this
<cfquery name="getmax" datasource="db">
SELECT MAX(field_ID) AS maxID FROM Table
</cfquery>
0
 
JohnLucaniaAuthor Commented:
The query already exists (<CFLOOP QUERY="MyInstallments"> ).
My question is how to find the last row/record from the query.
0
 
ExpertAdminConnect With a Mentor Commented:
Try this:

<CFLOOP QUERY="MyInstallments">

     <CFIF MyInstallments.CurrentRow EQ MyInstallments.RecordCount>

     ...Your last row logic here...

    </CFIF>


</CFLOOP>


M@
0
 
JohnLucaniaAuthor Commented:
great!
0
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.