Click to See Complete Forum and Search --> : Random records from a database??


Portmoon
02-17-2003, 05:59 PM
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 ‘Quiz’ 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

%>

Portmoon
02-18-2003, 12:29 PM
Thanks Dave for your comments.

Just to clarify.
An ASP is a page written in VBScript executed server side??
Can you 'embed' JavaScript within ASP and/or VBScript??

The ASP scripting language, 'ASP/JScript' can you reccommend any links to help me learn more??

I need to use a database for this quiz, what scripting language do you reccommend??

Thanks again!!

Portmoon

Portmoon
02-19-2003, 03:39 AM
Thanks Dave!

So, is there any way I can connect to a database using client side code? i.e JavaScript

As the quiz is not inteneded to go online and security is not an issue, I want to avoid having the code executed server side and work form client side only. Is this possible?

If this is not possible can I connect the database using VBScript and construct the remainder of the quiz in client side code??

Thanks!

Portmoon
02-19-2003, 09:00 AM
Okay Dave,

I want to thank you for all your comments and suggestions recently they have been very helpful, especially in clearing up a lot of my misconceptions.

Cheers!!