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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone suggest a randomizer??

Status
Not open for further replies.

Portmoon

Programmer
Feb 24, 2003
11
0
0
MY
Hi there!

The following piece of code is based on a quiz.
It currently takes 'all' the records (questions and 4 corresponding answer choices)
from the databaseand displays them on a web page.
The database is made up of 6 fields, 1 question, 4 answer and 1 correctID field that
holds the number that corresponds to the correct answer position in each case.
When the quiz is completed the SUB Mark() function calculates the score and displays questions,
correct answers and the score on another page.
What I wanted to know was how I could randomize the quiz.
i.e Retrieve 10 random questions from a database table of 30 thirty questions
and display them and their answers on a page?? (The file is called quiz.asp)

Any help and suggestions would be greatrly appreciated!!

Thanks,

Portmoon.



<%
' On Error Resume Next

Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;myDatabase.mdb&quot;)
SQL = &quot;SELECT * Quiz, conn, 3&quot;
Set rs = conn.Execute(SQL)

IF Request.Form.Count = 0 THEN
CALL List
ELSE CALL Mark
END IF

rs.close
conn.close
Set rs = Null
Set conn = Null

%>

<% SUB List() %>
<% session(&quot;referer&quot;) = Request.ServerVariables(&quot;HTTP_REFERER&quot;) %>
<FORM METHOD=&quot;POST&quot; ACTION=&quot;quiz.asp&quot;>
<OL>

<% DO WHILE NOT rs.eof %>
<LI><B><%= rs(&quot;question&quot;)%></B><BR>
<%
FOR i = 1 to 5
choice = rs.fields(i+1).value
IF choice <> &quot;&quot; THEN
%>
<INPUT TYPE=&quot;RADIO&quot; NAME=&quot;<%= rs(&quot;questionID&quot;) %>&quot; VALUE=&quot;<%= i %>&quot;>
<%= choice %>
<BR>
<%
END IF
NEXT
%>
<BR>
<%
rs.MoveNext
LOOP
%>
</OL>
<P><INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit quiz for scoring&quot;>
<INPUT TYPE=&quot;RESET&quot; VALUE=&quot;Clear All Answers&quot;>
</FORM>
<% END SUB %>

<%
SUB Mark()

correctCount = 0
total = 0
%>
<HTML>
<BODY BGCOLOR=&quot;#ffffff&quot;>
<%
FOR EACH x IN Request.Form
DO WHILE rs(&quot;questionID&quot;) <> CInt(x)
rs.MoveNext
LOOP
correctID = rs(&quot;correctID&quot;)
chosenID = CInt(Request.Form(x))
%>
<P>
<B>The question was: </B><%= rs(&quot;question&quot;) %><BR>
<B>Your choice was: </B><%= rs.fields(chosenID+1).value %>.<BR>
<%
IF chosenID = correctID THEN
correctCount = correctCount + 1
%>
<B>Your answer is correct.</B><BR>
<%
ELSE
%>
<B>The correct answer is: </B><%= rs.fields(correctID+1).value %>.<BR>
<B>Feedback: </B><%= rs(&quot;comment&quot;) %>.<BR>

<%
END IF
NEXT


rs.MoveFirst
DO WHILE NOT rs.eof
total = total + 1
rs.MoveNext
LOOP
%>


<P>You answered correctly <%= correctCount %> / <%= total %> questions
and your score is <B><%= Round(correctCount / total * 100) %>%</B>
<P><A HREF=&quot;<%= session(&quot;referer&quot;) %>&quot;>End Quiz.</A>
</BODY>
</HTML>
<% END SUB %>

 
Do a search for a random records in the forum search for this forum, this has been answered before with accompanying benchmarks by myself.

-Tarwn [sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Thanks a lot Tarwn,

Seems to be a popular subject and one you know a vast amount about.

Cheers for the link to the thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top