Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Movenext??

Status
Not open for further replies.

johnshutt

Technical User
Apr 11, 2002
6
GB
Right here goes, i need to be able to cycle through a recordset and display each "row" at a time, for a simple multiple choice quiz. I can display the first record, button cannot movenext. Where do i put the recordset.movenext statement if i am using forms to post the user selection back to the same page.

I have tried this once and have found that instead of moving next and refreshing the screen it simply re-opens the recordset. any thoughts? the code is below, if u want the dbase aswell lemme know.

Cheers for any help (in advanced. :))

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE>CP2023 - Computer Networks</TITLE>
<SCRIPT ID=serverEventHandlersVBS LANGUAGE=vbscript RUNAT=Server>

</SCRIPT>
</HEAD>
<BODY>
<%
dim Conn, Questions, Conn2, Answers
dim MyArray(20)
dim varBook

Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set Questions = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set Answers = Server.CreateObject(&quot;ADODB.Recordset&quot;)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Conn.Open &quot;Provider =Microsoft.Jet.OLEDB.4.0;&quot; &_
&quot;Data Source = C:\Inetpub\ &_
&quot;Persist Security Info=False&quot; ' CONNECTION TO DATABASE

strSQL = &quot;SELECT * FROM questions&quot; 'QUESRY THE TABLE QUESTION FOR ALL RECORDS

Questions.Open strSQL, Conn, adOpenDynamic 'OPEN RECORDSET

strSQL = &quot;SELECT * FROM student&quot; 'QUESRY THE TABLE ANSWERS FOR ALL RECORDS

Answers.Open strSQL, Conn, adOpenDynamic 'OPEN RECORDSET
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Curnq = questions(&quot;Question Number&quot;)
MyArray(Curnq)= Request.Form(&quot;Answer&quot;)
Response.Write Myarray(Curnq)

%>
<H2>You are currently on question number <%Response.Write Questions(&quot;Question Number&quot;)%><BR><BR><BR>

<%Response.Write Questions(&quot;Question&quot;)%><BR>



<form action=&quot;test.asp&quot; method=&quot;post&quot; name=Form>
<p><input TYPE=&quot;radio&quot; NAME=&quot;Answer&quot; VALUE=&quot;A&quot;><%Response.Write Questions(&quot;Answer A&quot;)%></p>
<p><input TYPE=&quot;radio&quot; NAME=&quot;Answer&quot; VALUE=&quot;B&quot;><%Response.Write Questions(&quot;Answer B&quot;)%></p>
<p><input TYPE=&quot;radio&quot; NAME=&quot;Answer&quot; VALUE=&quot;C&quot;><%Response.Write Questions(&quot;Answer C&quot;)%></p>
<p><input TYPE=&quot;radio&quot; NAME=&quot;Answer&quot; VALUE=&quot;D&quot;><%Response.Write Questions(&quot;Answer D&quot;)%></p>
<input type=&quot;submit&quot; Value =&quot;Forwards&quot;><%Questions.MoveNext%></form></H2>
</BODY>
</HTML>
 
You can't do it this way becuase when you resubmit the form by using the button, you effectively rerun both queries. So therefore you are resetting the recordset.

What you need is called pagination. Basically where you have several pages of forms, and you have links at the bottom for page 1,2,3,4......

There are some objects built into ASP to help do this. I would read through MSDN, and it should make it alot clearer.
 
Try reading all of the questions (if not too large) or just the key list into an array. Pop this into a hidden form field (use array to separated-list functions, like Join/Split in VB). Also, add a hidden field for the id of the current question - or perhaps change the value of the submit button to be the id of the next quetions.
If you add a PageObject design-time-control to your page, this may make things easier. Your code would be:

sub thisPage_OnEnter()
if thisPage.firstEntered then
'read in the data (see your original SQL)
else
'just fetch the next item
' ie unwind the item list from hidden field
' and get the text, or id of the next quetion
' if just the Id, then use SQL to fetch the text.
end if
end sub

You can use the PageObject to make it easier to add hidden fields too - just add a property to the Page Object, and use the
thisPage.setXYZ &quot;fred&quot;
or
sValue = thisPage.getXYZ()
to create and read hidden values.

Good luck. (Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top