7 Replies Latest reply on Mar 7, 2007 2:34 PM by lisarossiter

    Quick Online Test

    lisarossiter
      Hi,
      I am working on an online test. (Users read the question and submit their answers via drop down list). It all works very nicely if I put all the questions on one page (in one cfform). But...

      What I'd like to do is display only one question per page. When a user selects their answer and submits the form, it should move onto the next question until the test is complete. I'm struggling with how to accomplish this. Any help would be greatly appreciated.

      Lisa
        • 1. Re: Quick Online Test
          Level 7
          Any help would be greatly appreciated.

          This is what the session and application scope where created for.

          On your action page for each question just store the data in a relevant
          data format in the session scope. Then at the end you can process all
          the questions and answers as needed.


          • 2. Re: Quick Online Test
            lisarossiter Level 1
            thanks, that's helpful for storing the data, but my problem is getting the page to load the next record from the query to the page.

            I'm running one query on a page called exam.cfm that contains a simple cfform.
            This query pulls the test questions.
            Each time the form is submitted, it should reload the same page (exam.cfm) with the next test question (query result).

            Any help would be appreciated.
            • 3. Re: Quick Online Test
              Level 7
              I'm running one query on a page called exam.cfm that contains a simple
              cfform. This query pulls the test questions.
              Each time the form is submitted, it should reload the same page
              (exam.cfm) with the next test question (query result).

              Any help would be appreciated.

              Again, the session scope comes to your aid.

              You would put the query record set into a session variable. Then each
              time exam.cfm s displayed it would get the next question from this
              session variable. You will need some kind of pointer which could itself
              be a session, a form, an URL, or other variable depending on exactly how
              you want it to behave.
              • 4. Re: Quick Online Test
                lisarossiter Level 1

                <cfquery name="GetQuestions" datasource="ITTest">
                select Question
                from Questions
                WHERE active = 1
                Order by ID
                </cfquery>

                <cflock scope="session" timeout="60" type="exclusive">
                <cfset session.questions=GetQuestions>
                <cfset Request.Ses = Duplicate(Session.questions)>

                </cflock>

                <!---TEST OUTPUTS--->
                <cfdump var="#session.questions#">
                <cfoutput>#Request.Ses.Question#</cfoutput>
                <!---TEST OUTPUTS--->


                The dump does display all the data I'm looking for. And the Request.Ses.Questions will output the first record. I just can't figure out how to get the record number to change.

                I guess my problem is:
                how do I break it down to display one row in the cfform and move to the next row when the form is submitted again.

                Thanks again for all your help,
                The 'Newbie'
                • 5. Re: Quick Online Test
                  lisarossiter Level 1
                  I guess that I just don't understand the logic of how to move from row to row within the array.
                  • 6. Re: Quick Online Test
                    Level 7
                    <cfquery name="GetQuestions" datasource="ITTest">
                    select Question
                    from Questions
                    WHERE active = 1
                    Order by ID
                    </cfquery>

                    <cflock scope="session" timeout="60" type="exclusive">
                    <cfset session.questions=GetQuestions>
                    <cfset Request.Ses = Duplicate(Session.questions)>

                    </cflock>

                    <!---TEST OUTPUTS--->
                    <cfdump var="#session.questions#">
                    <cfoutput>#Request.Ses.Question#</cfoutput>
                    <!---TEST OUTPUTS--->

                    First of all, the locking and scope duplication you are doing is very
                    old school. If you are working on MX (6 & 7 and soon 8) generation of
                    ColdFusion it is no longer necessary. But if you are still in 5 or
                    earlier then my sympathy.

                    To you can use array notation to access individual rows of a record set.
                    I believe this was available on 4.5 and 5 versions of CF, it has been
                    so long for me. Anyway something like this should work.

                    <cfparam name="url.row" default="1">
                    <cfoutput>
                    #Request.Ses.Question[url.row]# <a href="exam.cfm?row=#url.row +
                    1#>Next Question</a>
                    </cfoutput>

                    If this does not work, you may need to convert the recordset into a
                    specific array for use with older versions of CF.



                    • 7. Re: Quick Online Test
                      lisarossiter Level 1
                      THANKS!!!!!!!!!!!!!