Jump to content

stop random repeating?


shaneR

Recommended Posts

Hi, could you please comment on the included code which displays questions from my database in a random order but sometimes the questions are re[eated in the same session.If you know how to stop this please show me how.Thanks all!!!

<%@ Language=VBScript %><%option explicit%><!-- #INCLUDE FILE = "connect_ama.asp" --><%	dim myrs	set myrs = server.createobject("ADODB.recordset")	myrs.open "select * from all_exams where ExamName ='" & Request.Form ("start") & "'" ,myconn	''''''''''''''''''''''''''''''''''''''''''''''''''	dim q_id1, q_id2, code, totaltime, ppercent, totalq, expire, examnameq_id1 = myrs("sq_id") q_id2 = myrs("eq_id")totaltime = myrs("totalTime")  totalq = myrs("totalQuestions")examname = myrs("ExamName")ppercent = myrs("ppercentage")code = myrs("code") expire = myrs("expireDate")myrs.Close session("totalquestions")=totalq''''''''''''''''''''''''''''''myrs.open "select * from q_bank where q_id between " & q_id1 & " and " & q_id2 ,myconn,3	'3=adOpenStatic,then only myrs.recordcount will work  ''''''''''''''''''''''''''''''dim totalrectotalrec = myrs.RecordCount session.Contents("ExamName")=Request.Form ("start")'Response.Cookies("totaltime")= cstr(totaltime) 'if myrs.Fields("ExpireDate") < Date  then'Response.Write "<h5>EXPIRED ''''''''<H5>"'end if' Response.Write "total time=" & totaltime & "<hr> total q=" & totalq & "<hr> total rec=" & totalrec &"<hr>"Dim num(),k,i,x,j,ans()redim num (totalq)redim ans (totalq)k = 1Randomize     For i = 1 To totalq         x = Round(Rnd * totalrec)						'give record count          For j = 1 To k            If num(j) = x Then               i = i - 1               Exit For            End If         Next         If j > k Then            num(k) = x            k = k + 1         End If     Next'''''''''''''''''''''''''''''''''''          for i=1 to totalq       ans(i)="Not Attempted"       'Response.Write i & " | " &num(i)& " | "       myrs.MoveFirst        myrs.Move num(i)-1       num(i)=myrs("q_id")       'Response.Write num(i) & " |<br> "     Next     Session("Questions")=num     Session("Answers")=ans     Session("Counter")=1     Session("examover")=0       Session ("examname")= examname     Session("ppercentage")= ppercent     ''''''''''''''''''''''''''''''''''closing order important'''''''''myrs.closemyconn.closeset myconn=nothingset myrs=nothing''''''''''''''''''''''''''''''''''Response.Redirect "exam_paper.asp"Response.Cookies(examname & "totaltime")= cstr(totaltime) %><HTML><HEAD></HEAD><BODY><form name=examform action="exam_paper.asp" method=post>  <input type=hidden name=qno value=1>  <input type=hidden name=totalq value=<%=totalq%>>  </form>  <script language="JavaScript">    document.examform.submit()  </script>        </BODY></HTML>

The include file:::

<%@ Language=VBScript %><%Response.Cookies("totaltime")="300"%><% Dim num(), k,ans(),totalq totalq=100 redim num(totalq) redim ans(totalq)     k = 1     Randomize     For i = 1 To totalq         x = Round(Rnd * totalq)         For j = 1 To k            If num(j) = x Then               i = i - 1               Exit For            End If         Next         If j > k Then            num(k) = x            k = k + 1         End If     Next     for i=1 to totalq        ans(i)="Not Attempted"       Response.Write num(i)& ".<br>"     Next     Session("Questions")=num     Session("Answers")=ans     Session("Counter")=1     Session("examover")=0    'Response.Cookies("totaltime")= "400" 'cstr(totaltime)   %>  <form name=examform action="exam1.asp" method=post>  <input type=hidden name=qno value=1>  <input type=submit name="xxxxxxxx" value=1>    </form>  <script language="JavaScript">    // document.examform.submit()  </script>   <P> </P></BODY></HTML>

Link to comment
Share on other sites

What database are you using? say for example if its SQL Server you can get the records from the database in random order using SQL query.SELECT * FROM tablename ORDER BY NEWID( )This query will return records in random order everytime.
The database im using is ACCESS 2000!!!Thankyou.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...