Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 681159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:27:10+00:00 2026-05-14T01:27:10+00:00

I need to loop over a query exactly 12 times to complete rows in

  • 0

I need to loop over a query exactly 12 times to complete rows in a form but rarely will the query return 12 rows. The cfquery endRow attribute doesn’t force the loop to keep going if the result is < 12. If it did that would be ideal to use something like cfloop query=”myQuery” endRow=”12″…
The 2 options that I have now are to skip the loop and write out all 12 rows but that results in a lot of duplicate code (there are 20 columns), or do a query of queries for each row which seems like a lot of wasted processing.
Thanks for any ideas.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:27:10+00:00Added an answer on May 14, 2026 at 1:27 am

    You can simply use

    maxrows="12"
    

    Although, I think there might be something wrong with your logic for having to do that. perhaps if you post some of our code, i can take a look a suggest a better approach.

    maxRows will do the trick for now though

    UPDATE

    Forgot to mention, maxrows have to be used with “cfoutput query”, as cfloop query won’t support it.

    In this case you’ll do somethig like:

    <cfoutput query="myQuery" maxRows="12">
    

    UPDATE of UPDATE

    After understanding exactly what you wanted, I wrote the following code which is pretty much what I reckon you need:

    <cfscript>
        qryTest = QueryNew("name,email");
        newRows = QueryAddRow(qryTest,5);
    
        tmp = querySetCell(qryTest, 'name', 'John', 1);
        tmp = querySetCell(qryTest, 'email', 'John@email.com', 1);
    
        tmp = querySetCell(qryTest, 'name', 'Paul', 2);
        tmp = querySetCell(qryTest, 'email', 'Paul@bob.com', 2);
    
        tmp = querySetCell(qryTest, 'name', 'George', 3);
        tmp = querySetCell(qryTest, 'email', 'George@bob.com', 3);
    
        tmp = querySetCell(qryTest, 'name', 'Ringo', 4);
        tmp = querySetCell(qryTest, 'email', 'Ringo@bob.com', 4);
    
        tmp = querySetCell(qryTest, 'name', 'Yoko', 5);
        tmp = querySetCell(qryTest, 'email', 'Yoko@bob.com', 5);
    </cfscript>
    
    <cfdump var="#qryTest#">
    
    <form name="test">
        <cfoutput>
            <cfloop from="1" to="12" index="ii">
                <cfif ii GT qryTest.recordCount>
                    <cfset tmp = QueryAddRow( qryTest, ii)>
                </cfif>
                Name: <input type="text" name="name_#ii#" value="#qryTest.name[ii]#"><br />
                Wmail: <input type="text" name="email_#ii#" value="#qryTest.email[ii]#"><br /><br />
            </cfloop>
        </cfoutput>
    </form>
    
    <cfdump var="#qryTest#">
    

    This will add new rows to your query dynamically should it be necessary (i.e. in case you don’t have 12 rows on your recordset)

    It’s mimicking a recordset just so you can copy and paste the code and see the results.

    hope it helps 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.