Hello there,
I am attempting to design a quiz program that will select one question at random from a database (MS Access) and display it along with its four possible answers in a form. The 慟uiz?table within the database contains 40 questions each with a unique number identifier (i.e QuizID field), four question fields (i.e Question1, Question2 etc) and a field containing the correct answer. The VBScript below connects the database to the form, however I do not know how to randomly generate a question and its choice of answers to the form??
Do I incorporate further SQL into the query in order to achieve this, or can I use VBScript or JavaScript?? If yes to any of these suggestions, how can I implement them??
Also, is it possible ensure that questions are not repeated with this code?
P.S Is it possible to use JavaScript in an ASP form and if so how and where is it declared??
Any help, suggestions, pointers, or advice would be very welcome!!
Thanks for reading.
<%
Dim accessDb, DSN1, dbConnection, dbQuery, recordSet
accessDb = "aDatabase.mdb"
DSN1 = "DRIVER={Microsoft Access Driver (*.mdb)};"
DSN1 = DSN1 & "DBQ=" & Server.MapPath(accessDb)
Set dbConnection = Server.CreateObject("ADODB.Connection")
dbConnection.Open DSN1
dbQuery = "SELECT Question FROM Quiz"
Set recordSet = dbConnection.Execute(dbQuery)
If ((RecordSet.EOF) OR (RecordSet.BOF)) Then
Response.Write("<h1>No database records found</h1>")
Else
Response.Write("<h1>Query Results</h1>")
Do Until recordSet.EOF
Response.Write(recordSet("Question"))
recordSet.MoveNext
Loop
End if
recordSet.Close
dbConnection.Close
%>
I am attempting to design a quiz program that will select one question at random from a database (MS Access) and display it along with its four possible answers in a form. The 慟uiz?table within the database contains 40 questions each with a unique number identifier (i.e QuizID field), four question fields (i.e Question1, Question2 etc) and a field containing the correct answer. The VBScript below connects the database to the form, however I do not know how to randomly generate a question and its choice of answers to the form??
Do I incorporate further SQL into the query in order to achieve this, or can I use VBScript or JavaScript?? If yes to any of these suggestions, how can I implement them??
Also, is it possible ensure that questions are not repeated with this code?
P.S Is it possible to use JavaScript in an ASP form and if so how and where is it declared??
Any help, suggestions, pointers, or advice would be very welcome!!
Thanks for reading.
<%
Dim accessDb, DSN1, dbConnection, dbQuery, recordSet
accessDb = "aDatabase.mdb"
DSN1 = "DRIVER={Microsoft Access Driver (*.mdb)};"
DSN1 = DSN1 & "DBQ=" & Server.MapPath(accessDb)
Set dbConnection = Server.CreateObject("ADODB.Connection")
dbConnection.Open DSN1
dbQuery = "SELECT Question FROM Quiz"
Set recordSet = dbConnection.Execute(dbQuery)
If ((RecordSet.EOF) OR (RecordSet.BOF)) Then
Response.Write("<h1>No database records found</h1>")
Else
Response.Write("<h1>Query Results</h1>")
Do Until recordSet.EOF
Response.Write(recordSet("Question"))
recordSet.MoveNext
Loop
End if
recordSet.Close
dbConnection.Close
%>