Finding the last row from cfquery

Posted on 2006-05-30
Last Modified: 2013-12-24
I have

<CFLOOP QUERY="MyInstallments">

<input .......>



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>
Question by:JohnLucania
    LVL 3

    Expert Comment

    try something like this
    <cfquery name="getmax" datasource="db">
    SELECT MAX(field_ID) AS maxID FROM Table

    Author Comment

    The query already exists (<CFLOOP QUERY="MyInstallments"> ).
    My question is how to find the last row/record from the query.
    LVL 7

    Assisted Solution

    Try this:

    <CFLOOP QUERY="MyInstallments">

         <CFIF MyInstallments.CurrentRow EQ MyInstallments.RecordCount>

         ...Your last row logic here...



    LVL 12

    Accepted Solution

    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 --->

    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 --->
        <!--- Do something else if this isn't the last row --->

    Author Comment


    Featured Post

    Network it in WD Red

    There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

    Join & Write a Comment

    Article by: kevp75
    Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
    When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now