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

x
  • 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.

Thanx,

P.S.  This is an awesome site!!!
0
WashDevSolutions
Asked:
WashDevSolutions
  • 3
1 Solution
 
SidFishesCommented:
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>
<cfelse>
Done!
</cfif>

#questions.qText#

</cfoutput>




0
 
SidFishesCommented:
oops

sb

<cfif start LTE questions.RecordCount>
0
 
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>
            </form>
      </cfif>
</cfloop>

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

0
 
SidFishesCommented:
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
0

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