Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:

Stepping through a CFLOOP, one record at a time

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!!!
  • 3
1 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>





<cfif start LTE questions.RecordCount>
WashDevSolutionsAuthor Commented:
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,

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now