Stepping through a CFLOOP, one record at a time

Posted on 2006-04-25
Last Modified: 2013-12-24
I am creating an online survey, where the questions are being generated from a database.  I want to display 1 question at at time (via CFFORM), get the answer for that questions, and write the answer to the answers table before I proceed to the next question.  Question:  How do I traverse through a CFLOOP, displaying one record at a time, only displaying the current record (i.e. displaying only record 3 of 10)?  Using the Query option will display all 10 records at a time, instead of displaying record 3 of 10 only.


P.S.  This is an awesome site!!!
Question by:WashDevSolutions
    LVL 36

    Accepted Solution

    something like...

    <cfset start =1>
    <CFOUTPUT query = "questions" startrow="#start#" maxrows="1">

    <cfif nextX LTE questions.RecordCount>
    <cfset nextx = start+1>
    <a href="questions.cfm?/start/#nextX#/">  Next &gt;&gt; </a>



    LVL 36

    Expert Comment



    <cfif start LTE questions.RecordCount>

    Author Comment

    Thanx SidFishes.

    I found that using CFOUTPUT with the QUERY= option would display all the records, ignoring the MAXROWS option (thats ColdFusion for you, ignoring its own rules).  Although your solution did not work right out of the box, it did put me in the right direction.  I came up with the following code, which accomplished what I neded, using CFLOOP:

    <!--- Note:  The name of this form is survey.cfm.  This code calls itself to display each question one at a time --->

    <cfparam name="url.CurrentQuestionID" default=1>

    <cfset Counter = #url.CurrentQuestionID#>
    <cfset CounterNext = url.CurrentQuestionID + 1>

    <CFloop query = "qGetQuestions" startrow="#Counter#" endrow="#Counter#">
          <cfif #Counter# LTE #qGetQuestions.RecordCount#>
                <form action="Survey.cfm?CurrentQuestionID=<cfoutput>#CounterNext#</cfoutput>" name="frmGetSurvey" method="post">
                      <!--- Code to display my question --->
                      <cfset Counter = #Counter# + 1>

    When you review this code, please review that the ENDROW and STARTROW must be the same in order for it to display 1 record at a time.  If I can figure out how to grant you the full point value for this question, I will.

    Thanx for you help,

    LVL 36

    Expert Comment

    not sure why the code i provided didn't work for the q as I use it  all the time with correct results, however given that the code helped in the eventual solution i think points should be awarded

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
    One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    729 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