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.
I need to loop over a query exactly 12 times to complete rows in
Share
You can simply use
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:
UPDATE of UPDATE
After understanding exactly what you wanted, I wrote the following code which is pretty much what I reckon you need:
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 😉